.htaccess中的“多视图"选项到底是什么? [英] What exactly does the Multiviews options in .htaccess?

查看:91
本文介绍了.htaccess中的“多视图"选项到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力制定访问规则,该访问规则需要重写一个添加路径的URL.

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]

此规则仅在我的Joomla网站上导致空白页,没有错误日志或消息. 奇怪的是,我制定的所有其他规则都运行良好:

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.

推荐答案

这是有关Apache内容协商的.

This is about Apache content negotiation.

MultiViews搜索是服务器进行隐式文件名模式匹配的位置,然后从结果中进行选择.

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

例如,如果您在根文件夹中有一个名为configuration.php(或其他扩展名)的文件,并且在htaccess中为一个名为configuration/的虚拟文件夹设置了规则,则您的规则会出现问题因为服务器将自动选择configuration.php(如果启用了MultiViews,则通常是这种情况).

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).

如果要禁用该行为,只需将其添加到htaccess中即可.
Options -MultiViews

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.

在某些共享主机上,谈判模块可能未启用.那将给您500错误.为避免此错误,默认情况下,您可以将指令封装在IfModule块中.

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>

这篇关于.htaccess中的“多视图"选项到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆