.htaccess 中的 Multiviews 选项究竟是什么? [英] What exactly does the Multiviews options in .htaccess?

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

问题描述

我一直在为需要重写一段 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/<的虚拟文件夹设置了规则/code> 那么你的规则就会有问题,因为服务器会自动选择 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.

在某些共享主机上,可能未启用 negotiation 模块.那会给你一个 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 中的 Multiviews 选项究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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