2

我有一个这样的网址:

http://my.site/apps/123

我想重定向到

http://my.site/app/123

使用 mod_rewrite。但是,当我使用这个 .htaccess 时:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^/apps/(.*)$ /app/$1 [R=301,L]
RewriteRule ^(.*)$ /index.php?/$1 [L]

我在日志中收到 500 和此错误:

Request exceeded the limit of 10 internal redirects due to probable configuration error. 
Use 'LimitInternalRecursion' to increase the limit if necessary. 
Use 'LogLevel debug' to get a backtrace.
[Thu Sep 13 12:58:13 2012] [debug] core.c(3112): [client 127.0.0.1] r->uri = /index.php

浏览器中的最终 URL 如下所示:

http://my.site/app/123?/apps/123

为什么 Apache 将 ?/apps/123 附加到 URL 上?

我想如果我可以避免这种情况,那么我可以避免这里的无限递归问题。

4

1 回答 1

1

如果您想将 my.site/apps/123 重定向到 my.site/app/123,只需使用:

RewriteEngine on
RewriteBase /
RewriteRule ^apps/(.*)$ app/$1 [L,R=301]

编辑 :

您在错误的位置添加了规则,试试这个而不是您的规则:

RewriteEngine on
RewriteBase /
RewriteRule ^apps/(.*)$ app/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !^index\.php
RewriteRule ^(.*)$ index.php?/$1 [L]
于 2012-09-13T12:27:08.313 回答