在重写规则,如果模式和替代皆以相同的字符串时,重写规则不起作用。为什么? [英] In RewriteRule if pattern and substitution begin with the same string, the RewriteRule doesn't work. Why?
问题描述
在这篇文章:<一个href="http://stackoverflow.com/questions/20274123/wheres-the-error-in-my-htaccess-rewriterule-regexp">My previous交 我问帮助一个奇怪的问题:一个正确的正则表达式是不工作的重写规则。之后的工作时间,我发现如何修正这个错误,我发现了这个奇怪的事情。
In this post: My previous post i was asking help for a strange issue: a correct regexp was not working in a RewriteRule. After hours of work i found how to fix the error and i found out this strange thing.
如果我写在.htaccess中的规则:
If i write this rule in .htaccess:
RewriteRule ^rankings\/[a-zA-Z0-9\-]+\.html$ /rankings.php
和键入此网址
http://www.mywebsite.net/rankings/classifica.html
我得到一个404错误。即使正则表达式是正确的,apache的RewriteEngine叙述不工作。 相反,如果我写这条规则:
I get a 404 Error. Even if the Regexp is correct, the apache RewriteEngine is not working. Instead, if i write this rule:
RewriteRule ^ran-kings\/[a-zA-Z0-9\-]+\.html$ /rankings.php
和键入此网址
http://www.mywebsite.net/ran-kings/classifica.html
一切工作正常。我做了很多其他的测试,不同的规则和网页,我总是得到同样的问题。 我得出的结论是,如果图案和替代开始与同一字,所述重写规则不起作用。
Everything works fine. I made many other tests with different rules and pages and i always got the same problem. The conclusion i came to is that if the pattern and substitution begin with the same word, the RewriteRule doesn't work.
为什么这可能吗?任何人都知道为什么出现这种情况?
How come is this possible? Anybody knows why this happens?
推荐答案
其实真正的问题是的 多视图
选项 。 多视图
允许的文件扩展名的替换,所以你可以调用像 http://www.example.com/page.php $ C的URL $ C>使用
http://www.example.com/page
。
Actually real problem is the MultiViews
option. Multiviews
allow substitutions of file extensions, so you can call an URL like http://www.example.com/page.php
using http://www.example.com/page
.
使用该行对你的.htaccess的顶部来禁用它:
Options -MultiViews
这篇关于在重写规则,如果模式和替代皆以相同的字符串时,重写规则不起作用。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!