2010-05-30 139 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

相关问题