Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does the Multiviews options in .htaccess?

I've been struggling a lot with an access rule that needed to rewrite one piece of URL adding a path.

RewriteRule ^(configuration/.+)$ application-server/$1 [L,NC,R=301,NE] 

This Rule caused just a blank page on my Joomla site with no error log or messages. The curious thing is that all other rules I had worked perfectly:

RewriteRule ^(log/.+)$ application-server/$1 [L,NC,R=301,NE] RewriteRule ^(monitor/.+)$ application-server/$1 [L,NC,R=301,NE] 

in the end, I've found in a forum a suggestion to use the following option:

Options -Multiviews 

That actually solved the issue, however I wonder if there can be any side effects on other Rules when using this option.

like image 601
user2824073 Avatar asked Aug 21 '14 09:08

user2824073


People also ask

How do I turn off Apache MultiViews?

In /etc/apache2/httpd. conf you should find the section starting <Directory "/Library/WebServer/Documents"> and remove MultiViews from the Options directive there.

How do I know if htaccess rewrite is working?

Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.


1 Answers

This is about Apache content negotiation.

A MultiViews search is where the server does an implicit filename pattern match, and choose from amongst the results.

For example, if you have a file called configuration.php (or other extension) in root folder and you set up a rule in your htaccess for a virtual folder called configuration/ then you'll have a problem with your rule because the server will choose configuration.php automatically (if MultiViews is enabled, which is the case most of the time).

If you want to disable that behaviour, you simply have to add this in your htaccess
Options -MultiViews

This way, your rule will be now evaluated because content negotiation is disabled.

Edit

On some shared hostings, the negotiation module might not be enabled. That would give you then a 500 error. To avoid this error, you can, by default, encapsulate the directive in an IfModule block.

<IfModule mod_negotiation.c>     Options -MultiViews </IfModule> 
like image 155
Justin Iurman Avatar answered Sep 24 '22 15:09

Justin Iurman