Reputation: 1341
I know that there are a lot of questions about this topic here, but I am unable to get my .htaccess
to work.
All traffic should be redirected to /index.php
using RewriteEngine
Using the following .htaccess
:
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.*) index.php [NC,QSA,R]
I get the following error (using http://localhost/foo
, should be redirected to: http://localhost/index.php
:
The requested URL /index.php was not found on this server.
Output from ls
in /var/www/
:
drwxr-xr-x 2 www-data root 4096 May 30 16:57 .
drwxr-xr-x 19 root root 4096 May 30 16:57 ..
-rw-r--r-- 1 root root 92 May 30 17:34 .htaccess
-rw-r--r-- 1 www-data root 4 May 30 16:50 index.php
The configuration for the path:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Am I missing something?
Upvotes: 1
Views: 2223
Reputation: 74028
First of all, since you seem to have access to the server configuration, there's no need to use an .htaccess
file. Just add the rewrite directives inside your Directory
directive.
The problem with your rewrite rules seem to be the difference between the Directory
and .htaccess being /var/www
, but your document root is /var/www/html
. In order to find /index.php
(note the leading slash), it must be located in the document root, /var/www/html
and not in /var/www
.
Upvotes: 0
Reputation: 41219
You can use the following with absolute target path:
RewriteEngine on
RewriteCond %{REQUEST_URI} !index\.php$
RewriteRule (.*) /index.php [R,L]
Upvotes: 1