.htaccess mod_rewrite-停止添加问号和原始查询

.htaccess mod_rewrite-停止添加问号和原始查询,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有这样一个URL: http://my.site/apps/123 http://my.site/app/123?/apps/123 我想重定向到它 http://my.site/app/123 使用mod_重写。但是,当我使用此.htaccess时: RewriteEngine on RewriteCond $1 !^(index\.php) RewriteRule ^/apps/(.*)$ /app/$1 [R=301,L] RewriteRule ^(.*)$ /index.php

我有这样一个URL:

http://my.site/apps/123
http://my.site/app/123?/apps/123
我想重定向到它

http://my.site/app/123
使用mod_重写。但是,当我使用此.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/apps/123
http://my.site/app/123?/apps/123
为什么Apache会在URL上附加?/apps/123?


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

如果要将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]

我还是有同样的问题。需要说明的是:我在新的URL上附加了“/apps/123”。/apps/123重定向到/app/123?apps/123。然后,由于无限递归,我得到了一个500。你的规则
RewriteRule^(.*)$/index.php?/$1[L]
是导致这个的原因,你真的需要它吗?不,index.php重写工作正常。如果我完全删除了它,我仍然会遇到同样的问题(例如,如果我删除了你编辑的答案的最后两行)。奇怪的是,它现在都工作了,所以我勾选了这个答案。不知道最初的问题是什么——但重启Apache并清除Firefox中的缓存解决了问题。