Getting errors when access one file using Kohana Framework - kohana-3.2

I use Kohana v=3.2 and want to access check.php that located on webroot
webroot
modules
application
system
index.php
check.php
.htaccess
but when I access domain.com/check.php, I found
HTTP_Exception_404 [ 404 ]: Unable to find a route to match the URI:
check.php
Can anyone help so I can access the file domain.com/check.php ?

Below is the default .htaccess file (example.htaccess) that ships with Kohana.
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
To enable your check.php file to be executed ensure that your .htaccess file contains the following lines at the bottom:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php/$0 [PT]

Related

Configuring htaccess file for React Router on Apache Server

I have deployed a React app with React Router to my Bluehost server, and need to configure the htaccess file to redirect all of my routed URLs (/portfolio, /about, etc) to index.html instead of trying to fetch a new file from the server and throwing a 404.
I have read about countless similar problems in which the solution seems to be to add this into your htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
I tried this, but I am still getting 404's when I try to visit any page of my site directly that isn't the homepage. I'm wondering if there is anything else in my existing htaccess file that is preventing the above code from working?
There was some code already in there from Bluehost, and I see another IfModule statement, so I'm wondering if that one is overwriting the first one. However I am afraid to edit it and break something, as it clearly says "do not edit." Here is my full htaccess code:
Header always set Content-Security-Policy: upgrade-insecure-requests
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
# END WordPress
Any ideas? I've double-checked that my BrowserRouter is set up correctly and also tried a few other htaccess configurations. I want to avoid using HashRouter or Node if possible but am getting frustrated. I can provide my React code as well if needed, but I'm pretty sure the error is not with the React setup.
You can create a virtual host file in the /etc/apache/sites-available folder and add this:
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/httpd/example.com
<Directory "/var/www/httpd/example.com">
...
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
This worked for me

Configuring .htaccess file to serve angular and api routes

I am lost with the configuration of my .htaccess file. I have a website serving the client part (angular.js app) and api routes, which are handled with the slim framework.
My html pages are served with the ui-router, but in order to handle the page refresh, I have to do an url rewrite.
That's my file so far :
DirectoryIndex index.html index.php
#
# Redirect all to index.php
#
RewriteEngine On
# if a directory or a file exists, use it directly (static assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#if route starts with "api", route to index.php (slim framework)
RewriteRule ^api/ index.php [L]
#else (it means we are serving the angular routes)
RewriteRule ^(.*) /index.html [NC,L]
It's, of course, not working. The real problem is that I don't know if my logic is good at first (or I am far far far far away...), and then how to write it (I am new to apache syntax and I don't really understand everything).
With 2 virtual hosts
API htaccess:
RewriteEngine On
# Redirect Trailing Slashes
RewriteRule ^(.*)/$ /$1 [L]
# Redirect Root
RewriteRule ^$ api.php [L]
# Handle API Requests
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api.php [L]
Front virtual host:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html (html5mode)
RewriteRule ^ /index.html
# Redirect /api to API virtual host
<Location /api>
ProxyPass http://127.0.0.1:8090 # Change here to the API virtual host binding
</Location>
The front virtual host will serve the requested file if it exists (except for /api/*), or will serve index.html if it does not. All /api requests will be forwarded to API virtual host. The API virtual host will serve any existing file, or will rewrite to api.php, which will handle your API calls.
With 1 virtual host
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} ^/api/
RewriteRule ^ api.php [L]
# If the requested resource doesn't exist, use index.html (html5mode)
RewriteRule ^ /index.html [L]
Same behavior as above
WARNING: trying to include a non-existant file into the angular app may produce an infinite loading loop (index.html will load, then it will load the non-existant file, which will be index.html due to html5mode, etc...)

.htaccess - Redirect everything to homepage except one directory

I'm creating an AngularJS app and want to avoid the # in the URL. I learned that I needed to add the following .htaccess rules to make it work:
RewriteEngine On
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
That worked great. However, now my calls to my web services are not working. The web service files are inside an /api/ directory, e.g. http://example.com/api/. My guess is that when the api calls try to access those files, they also get redirected and break. So how can I modify the rules above to redirect everything to the homepage, except links that are going to any file inside the api folder? I tried to find an existing answer to this, but while there were many similar ones, none of them was exactly what I needed. Thanks!
I found the code I needed:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /
That's all you need. Got it from: https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-pretty-urls-on-apache-using-htaccess/

Cake site not finding images nor CSS files after moving it to my localhost?

I'm using cake1.3.5
I recently moved a live working site into my localhost:
I set config.php to my local database but when I enter the site, I see this:
Is it there any additional step I am missing (concerning the file path or something)?
Cake directs all its call to webroot folder (by default called URL rewriting). This is achieved via .htaccess file in the document root, which MUST have (for URL rewriting to work)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
The .htaccess file inside the webroot folder should contain
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d // this line traps requests for directory
RewriteCond %{REQUEST_FILENAME} !-f // this line traps requests for file names
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
The two lines RewriteCond %{REQUEST_FILENAME} !-d & RewriteCond %{REQUEST_FILENAME} !-f are essential in parsing requests for directories and file names.
The line RewriteRule ^(.*)$ index.php?/$1 [QSA,L] deals with anything which is not a file or directory.
Check if mod_rewrite is enabled or not.
There must be two .htaccess file, one in the root folder and other one in the webroot folder. The contents of both these .htaccess files must be different.
You may wanna check out URL rewriting
You can turn off URL rewriting from Core Configuration
having gone through the same scenario, it turns out that the localhost did not recognise short style tags are only available when they are enabled in php.ini configuration file on servers.
When I changed the tags to all the pages appeared normally.

htaccess various rewriting needs

I have a website let's say http://myweb.com and I want to migrate it into a subfolder of the root directory http://myweb.com/subfolder/
I need the following things, I guess using the htaccess file:
1) Redirect all non-www to www
2) Redirect all files in the root to equivalent files in the subfolder at the same time changing all htm extension to html, that is a file in the root file.htm must be rewritten to a file in the subfolder like subfolder/file.html
3)I want that in the address is still displayed www.myweb.com rather than www.myweb.com/subfolder
is it all possible? And how? Thanks for any answer
Add these rules to the htaccess in your document root:
RewriteEngine On
# 1) Redirect all non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
# 2) Redirect all files in the root to equivalent files in the subfolder
# at the same time changing all htm extension to html
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)\.htm$ /subfolder/$1.html [L]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)$ /subfolder/$1 [L]
The last rules don't have the R flag so they won't cause an external redirect (thus changing what's in the browser's URL address bar).

Resources