htaccess 重定向与动态变量冲突
我正在一个旧的 CMS 中工作,它使用 htaccess 将带有 GET 变量的 URI 重写为更用户友好的内容。
RewriteEngine on
RewriteRule ^animals/(.*)/ secondary.php?page=$1
RewriteRule ^animals/(.*) secondary.php?page=$1
结果(正确地)出现
http://www.example.com/animals/duck
问题是我现在需要将其中一些页面重定向到新页面。我已经尝试过:
Redirect 301 /animals/goose http://www.example.com/animals/fowl
重定向几乎可以工作,但它在重写的 URI 末尾添加了“?page=goose”:
http://www.example.com/animals/fowl?page=goose
我尝试过使用 RewriteRule 以及 RewriteCond,但不幸的是我没有运气。任何帮助将不胜感激。
I'm working in an old CMS that uses htaccess to rewrite URIs with GET variables into something more user friendly.
RewriteEngine on
RewriteRule ^animals/(.*)/ secondary.php?page=$1
RewriteRule ^animals/(.*) secondary.php?page=$1
which results (correctly) in
http://www.example.com/animals/duck
The problem is I now need to redirect some of those pages to new pages. I've tried:
Redirect 301 /animals/goose http://www.example.com/animals/fowl
The redirect almost works, but it adds "?page=goose" to the end of the rewritten URI:
http://www.example.com/animals/fowl?page=goose
I've tried using RewriteRule as well as RewriteCond, but unfortunatley I'm having no luck. Any help would be immensely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将其放在其他规则之前,而不是重定向语句。
R=301
用于重定向,L
表示相关规则是要处理的最后一个规则。此外,您还可以轻松地使斜杠(就像任何其他字符一样)带有问号可选,而不是有两个规则。
Try placing this before the other rules instead of the Redirect statement.
R=301
is for the redirect andL
signals that the rule in question is the last rule to be processed.Also you can easily make the slash (just like any other character) optional with a question mark, instead of having two rules.