Htaccess重写导致无限重定向


htaccess rewrite causing infinite redirect

我需要从像

这样的东西重写一个URL

/index.php?option=com_scoreboard&view=scoreboard&agent=001C0000016rJeUIAU

/quote/?agent=001C0000016rJeUIAU .

这是我目前得到的。

RewriteCond %{QUERY_STRING} agent=('w+)&?
RewriteRule ^index.php /quote/?agent=%1 [R=301,L]

它工作得很好,但是它以一个无限循环结束。我也知道为什么,因为它一直在寻找agent=。我应该在我的重写规则中添加什么来阻止这种情况?

我也试过像

这样的变化
RewriteCond %{QUERY_STRING} ^option='w+?&agent=('w+)&?
RewriteRule ^index.php /quote/?agent=%1 [R=301,L]

但是它以同样的无限重定向结束。

这也适用于Joomla网站,如果有帮助的话。所以在此规则之后是标准的Joomla重写。

多谢了!

最好改为THE_REQUEST变量,并确保将此规则保留为第一条规则:

RewriteCond %{THE_REQUEST} /index'.php'?agent=('w+)
RewriteRule ^ /quote/?agent=%1 [R=301,L]

THE_REQUEST变量表示Apache从浏览器接收到的原始请求,并且在执行一些重写规则后不会被覆盖。