【发布时间】:2012-10-24 20:10:05
【问题描述】:
已解决:)
RewriteCond %{THE_REQUEST} index.php
RewriteRule index.php(.*)$ http://%{HTTP_HOST}$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
我配置了一个重定向,以便我可以打开 http://example.com/controller/action 和 ModRewrite 将内部请求路由到 ...index.php/controller/action。
如果用户自动打开http://example.com/index.php/controller/action,我想将他重定向到 index.php/controller/action(301 重定向)。但现在我得到了无限循环的重定向。
有没有机会将内部重定向分离到引导 index.php 并防止一个用户可以使用 index.php 子路径打开 url?
我试过这个,但不起作用(无循环):
RewriteCond %{REQUEST_URI} index.php/(.*)
RewriteRule ^index.php/(.*)/$ http://%{HTTP_HOST}/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
【问题讨论】:
-
你不应该真的需要用第一个条件/规则重写......因为两个网址应该做完全相同的事情。如果他们没有你有一个糟糕的实施;-)
-
第一条规则使外部重定向(301)第二条内部重定向。所以它不一样;)。当用户打开带有 index.php 的 url 时,他应该重定向到没有 index.php 的版本。但是没有index.php的版本必须内部重定向到引导文件index.php,这就是冲突。
-
Opps...你是对的...完全错过了。但是,如果您使用相同的 shceme,只需将 url 按原样重定向到新主机应该做同样的事情。我的意思是,就您的路由器而言,
/index.php/controller/action与/controller/action相同。通常,您的最后一条规则如下所示:RewriteRule ^(.*)$ /index.php [L]不是缺少捕获组。
标签: php .htaccess mod-rewrite