的.htaccess边缘情况
问题描述:
我正在使用的.htaccess这些规则和条件,把这些的.htaccess边缘情况
http://www.example.com/index.php/about/history
http://www.example.com/about/history/index.php
到
http://www.example.com/about/history
的.htaccess
# ensure there is no /index.php in the address bar
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ $1 [R=301,L,NS]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]
除了有这样的情况,如果URL是
http://www.example.com/about/index.php/history/
这将导致无限循环的重定向。现在我知道这可能是罕见的,但我希望它不会发生,如果可能的话。我如何改变我的规则以适应此?
答
如果我理解正确的话你只是想徘徊无论它似乎删除的index.php?在这种情况下,您的解决方案过于复杂。你可能想是这样
RewriteRule ^(.*)index\.php/(.*)$ $1$2 [NS,NC,L,R=301]
这应该是唯一的规则,无需对的RewriteCond的以及
这条规则其中URL的index.php开始在第一个例子/像不起作用。但是,它与其他示例一起工作。 – alex 2009-05-25 04:24:29