htaccess url 屏蔽 mod 重写

发布于 2024-11-19 19:56:32 字数 518 浏览 2 评论 0原文

我做了一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2024-11-26 19:56:32

如果您在此规则之后添加另一个与您的“反向”模式匹配的重写规则,并将两者标记为 [L]ast 规则,则可能会起作用。我首先重写 url 以包含查询字符串,并将该字符串添加到下一条规则中。之后我们[R]重定向浏览器。

RewriteRule ^(.)/(.)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3 [L]
RewriteRule ^(.+) $1%{QUERY_STRING} [C]
RewriteRule ^teams.php?competition=([a-zA-Z0-9]+)&season=([a-zA-Z0-9]+)&teamid=([a-zA-Z0-9]+)$ $1/$2/clubs/$3/ [R=301,L]

请注意,我尚未测试此规则或第二条规则的正则表达式。可能需要稍微调整字符范围。另外,我还没有测试第二条规则中的查询字符串重写。

编辑:请参阅此处了解 mod_rewrite 的一些常见用例: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

If 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.

RewriteRule ^(.)/(.)/clubs/(.*)/$ teams.php?competition=$1&season=$2&teamid=$3 [L]
RewriteRule ^(.+) $1%{QUERY_STRING} [C]
RewriteRule ^teams.php?competition=([a-zA-Z0-9]+)&season=([a-zA-Z0-9]+)&teamid=([a-zA-Z0-9]+)$ $1/$2/clubs/$3/ [R=301,L]

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文