2010-05-30 142 views
2

我試圖將所有請求內部重定向到index.php,並使用.htaccess文件從外部重定向包含index.php的所有請求。將URL重寫爲index.php,但避免在URL中使用index.php

所以像http://host/test網址應該由index.php文件和URL處理像http://host/index.php/test應該被重定向到http://host/test,然後通過index.php文件處理(不將瀏覽器重定向到index.php)

我嘗試以下,但總是提示「重定向過多...」:

RewriteRule ^index\.php/?(.*)$ /$1 [R,L] 
RewriteRule .* index.php/$0 [L] 

回答

2

你需要看看在請求行的URL,看是否/index.php/…已請求:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*) 
RewriteRule ^index\.php/?(.*) /$1 [R,L] 
RewriteCond $0 !^index\.php($|/) 
RewriteRule .* index.php/$0 [L] 
0

除此之外,如果您想在不重定向瀏覽器的情況下執行此操作,那麼您不希望使用[R]選項,這意味着R將瀏覽器導向。

試試這個:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteRule ^(index.php/)?.* index.php [L] 
</IfModule> 
+0

等待,這不利於;我誤解了一些問題。 – 2010-05-30 13:15:41

相關問題