To start off I know how to do a simple redirect to a 404
when a page doesn't exist with.
ErrorDocument 404 /index.php
Is what I want to do is a physical redirect to the index page. So if a user types in mydomain.com/abc
and that page doesn't exist it does an actual redirect TO the index page. I don't want the url to remain the same with the bad address. Yes I know its not a big deal but it bugs me. I could accomplish this by having a custom 404 page redirect to the homepage but I don't want this.
I've tried this with the [R]
redirect flag and obviously it doesn't work.
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(.*)$ /index.php [L,R]
Update
This is the error I get it rewrites the url to mydomain.com/index.php
I tried to remove the index.php
with just /
and it didn't redirect but gave the same error below.
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept
cookies.
Do this:
Explanation:
checks whether the file has extension:
If not, checks whether file is present:
If not a file, checks whether it is a folder which is present:
If not append
.php
. If/
is present at the end, remove it and append.php
Checks whether the
.php
appended or whatever extension file is actually a file which is present:check whether it is a directory:
If not, then it is a invalid file request and redirects it to
/
RewriteRule ^(.*)$ / [L,R]This should be your mod_rewrite based 404 handling:
However I am not sure what are you doing in your first rule? Are you trying to add
.php
to each request URI?