htaccess url 屏蔽 mod 重写
我做了一些 URL 屏蔽,效果非常好。我现在正在尝试解决一个问题:
RewriteRule ^(.*)/(.*)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3
通过上述方法,我可以通过两种方式访问同一页面,www.domain.com/premier-league/2010-2011/arsenal/
和 >www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal
在我的重写规则中是否有一种方法可以重定向URL(最好是 301)是有人通过不整洁的方式“www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal
”来实现的?
提前致谢
I have done some URL masking and it all works very nicely. I have one issue that I am trying to resolve now:
RewriteRule ^(.*)/(.*)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3
with the above I can access the same page 2 ways, www.domain.com/premier-league/2010-2011/arsenal/
and www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal
is there a way in my rewrite rule I can redirect the URL (301 ideally) is someone does it through the untidy way "www.domain.com?competition=premier-league&season=2010-2011&teamid=arsenal
"?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在此规则之后添加另一个与您的“反向”模式匹配的重写规则,并将两者标记为 [L]ast 规则,则可能会起作用。我首先重写 url 以包含查询字符串,并将该字符串添加到下一条规则中。之后我们[R]重定向浏览器。
请注意,我尚未测试此规则或第二条规则的正则表达式。可能需要稍微调整字符范围。另外,我还没有测试第二条规则中的查询字符串重写。
编辑:请参阅此处了解
mod_rewrite
的一些常见用例: http://httpd.apache.org/docs/2.0/misc/rewriteguide.htmlIf you add another rewrite rule after this one that matches your 'inverse' pattern, and mark both as the [L]ast rule, that might work. I first rewrite the url to include the query string, and [C]hain that one to the next rule. After that we [R]edirect the browser.
Note I haven't tested this or the regex of the second rule. Might need to adjust the character ranges a bit. Also I haven't tested the query string rewrite in the second rule.
Edit: See here for some common use cases of
mod_rewrite
: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html