2013-06-27 101 views
0

注意,我在StackOverflow上發現了類似的問題,但是他們沒有按照我的需要工作。從URL中刪除/index.php/ .htacess

我有一個網址,如:

http://www.example.com/index.php/test 

我想刪除的index.php目錄,因此如果上述輸入它會去:

http://www.example.com/test 

這似乎工作

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L] 

但是如果URL是:

http://www.example.com/index.php?option=example 

它變成

http://www.example.com/?option=example 

所以的index.php應該只有當它就像我的第一例的目錄中刪除。

此外,如果您在輸入實例:

http://www.test.example.com/index.php/index.php/dfd 

應該去

http://www.test.example.com/dfd 

任何想法?

回答

1

以下會的規則:

  • 不適用於/index.php?o=a

  • 重定向到/index.php/index.php/dfd/dfd

  • 重定向到/index.php/index.php/dfd?a=b/dfd?a=b

  • 重定向/index.php/index.php?a=b/index.php?a=b

RewriteCond %{QUERY_STRING} .+ 
RewriteRule ^index\.php(/index\.php)+/?$ /index.php [R=302,L,QSA,NC] 

RewriteCond %{QUERY_STRING} ^$ [OR] 
RewriteCond %{REQUEST_URI} !index\.php/?$ 
RewriteRule ((^|/)index\.php)+/?(.*)$ /$3 [R=302,L,QSA,NC] 
+0

看起來非常接近按需工作。當我嘗試這個例如:http://example.com/index.php/index.php?option=random它不會刪除/index.php/該網址應去http://example.com/ index.php?option = random否則你的解決方案看起來很完美。 – cchiera

+0

感謝您的快速響應。當使用更新的代碼時,站點500s。 – cchiera

+0

要注意,我認爲它在日誌中放入的實際錯誤(如果有幫助)是:由於可能的配置錯誤,請求超過了10個內部重定向的限制。如果需要,使用'LimitInternalRecursion'來增加限制。使用'LogLevel debug'來獲得回溯。 – cchiera