Reputation: 1076
So, I have in my web root an admin.php file and I want every time someone writes /admin to be redirected to that /admin.php.
I wrote in my htaccess
RedirectMatch 301 ^/admin$ /admin.php
However, I get an error from apache "file not found".
I created an empty /admin folder and it works...
Then I try to have an other (also non existant folder) to redirect to admin.php. So I write
RedirectMatch 301 ^/blah$ /admin.php
and it works...
Finally I delete the admin.php and I have the thing redirected to another .php
RedirectMatch 301 ^/admin$ /index.php
and it works again...
I understand that for some reason apache messes things up when the folder to be redirected from has the same name with the .php
With Rewrite I can do the redirection without any problems but I was wondering if it was also possible with just a Redirect... Maybe I am missing something here...
Upvotes: 2
Views: 118
Reputation: 785481
apache messes things up when the folder to be redirected from has the same name with the .php
This is due to Apache's content negotiation module that runs before mod_rewrite
, mod_alias
and makes Apache web server match extensions of files. e.g. /file
can be in URL but it will serve /file.php
.
To fix this behavior disable MultiViews
by placing this rule on top of your .htaccess:
Options -MultiViews
Upvotes: 3