Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

mod rewrite - 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.

question from:https://stackoverflow.com/questions/25423141/what-exactly-does-the-multiviews-options-in-htaccess

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...