2013-06-27 102 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