Jump to content

Recommended Posts

Hi everyone,

 

I have noticed that all our company's (Debian) webservers with a recent version of Apache automatically map http://domainname.com/index to a matching entry in the DirectoryIndex directive (index.html, index.php, etc.). So, if there's an index.php present, Apache directs http://domainname.com/index to the index.php file. I don't (knowingly) have a mod_rewrite rule active doing this, it seems to be happening "by itself".

 

I want to stop this behaviour as it's messing up a mod_rewrite rule I'm making because /index gets evaluated as being a file!

 

Does anybody know where the configuration of this behaviour is?

 

Thanks in advance.

 

You might be more accurate?

 

Accurate? Do you mean specific? ???

 

The problem is quite simple.

 

"http://www.mydomain.com/index" should normally (without a mod-rewrite rule active) lead to a 404 error, because "index" is not a valid file or folder in my webroot. Instead, Apache routes the "http://www.mydomain.com/index" request to whatever file is available from the DirectoryIndex directive (for example, index.php or index.html), effectively making it a direct call to for example "http://www.mydomain.com/index.html" internally (this doesn't show in the address bar of course).

 

In my mod_rewrite rules I have set in the conditions to not rewrite files and folders with:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

 

What happens now is that in my MVC application http://www.mydomain.com/index/login does not get directed to the login action in my index controller file, but because /index gets evaluated as a file it doesn't fill the route $_GET variable through the rewrite action above.

 

This is not a mod_rewrite issue I think (otherwise I'd have posted it in the correct sub-forum), my rewrite rules work fine (at least on my developent XAMPP installation).

 

When I comment out the first rewrite condition (so files will get rewritten), my $_GET looks like "index.php/login" instead of "index/login" which it should be.

 

I hope it's more clear now...

I have found the answer through another forum. I feel pretty stupid as it's actually quite simple. The server has Options MultiViews enabled by default which causes this behaviour. Adding Options -MultiViews to my .htacces solved everything.

 

http://httpd.apache.org/docs/2.2/content-negotiation.html#multiviews

 

Options -MultiViews

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.