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 重写。
非常感谢!
Bette to THE_REQUEST
variable instead and make sure to keep this rule as the first rule:
RewriteCond %{THE_REQUEST} /index\.php\?agent=(\w+)
RewriteRule ^ /quote/?agent=%1 [R=301,L]
THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,在执行某些重写规则后它不会被覆盖。
我需要从
之类的东西重写一个 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 重写。
非常感谢!
Bette to THE_REQUEST
variable instead and make sure to keep this rule as the first rule:
RewriteCond %{THE_REQUEST} /index\.php\?agent=(\w+)
RewriteRule ^ /quote/?agent=%1 [R=301,L]
THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,在执行某些重写规则后它不会被覆盖。