2009-05-25 52 views
2

我正在使用的.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/ 

這將導致無限循環的重定向。現在我知道這可能是罕見的,但我希望它不會發生,如果可能的話。我如何改變我的規則以適應此?

More info here about my .htaccess

回答

2

如果我理解正確的話你只是想徘徊無論它似乎刪除的index.php?在這種情況下,您的解決方案過於複雜。你可能想是這樣

RewriteRule ^(.*)index\.php/(.*)$ $1$2 [NS,NC,L,R=301] 

這應該是唯一的規則,無需對的RewriteCond的以及

+0

這條規則其中URL的index.php開始在第一個例子/像不起作用。但是,它與其他示例一起工作。 – alex 2009-05-25 04:24:29