使用RewriteRule重定向,保持密钥重定向到新URL(Redirect with RewriteRule keeping keys redirected to the new url)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
使用RewriteRule重定向,保持密钥重定向到新URL(Redirect with RewriteRule keeping keys redirected to the new url)

我有这个网址:

somesite.org/news.php?a=0&b=20

我想要的 - 重定向到

somesite.org/specialnews/20

如果你看到 - 键a表示类型。 所以a = 0意味着特殊新闻。 所以我需要只重定向那些具有= 0和基本网址( news.php )的网址到/specialnews/ 。

我试过的是:

RewriteCond %{QUERY_STRING} ^a=0&b=(.*)$ RewriteRule ^news\.php\?a\=0&b\=(.*)$ specialnews/$2 [R=301]

没有帮助;)需要指示。

I got this url:

somesite.org/news.php?a=0&b=20

What I want - redirect it to

somesite.org/specialnews/20

If you see - key a means the type. So a=0 means specialnews. So I need redirect only those urls, that have a=0 and base url (news.php) also to /specialnews/.

What I've tried is:

RewriteCond %{QUERY_STRING} ^a=0&b=(.*)$ RewriteRule ^news\.php\?a\=0&b\=(.*)$ specialnews/$2 [R=301]

didn't help ;) Need directions.

最满意答案

您无法在RewriteRule中匹配查询字符串参数,但您可以通过RewriteCond捕获参数并在RewriteRule中使用它(带%):

RewriteCond %{QUERY_STRING} a=0&b=(.*) RewriteRule ^news.php /specialnews/%1? [R=301]

You can't match query string params in RewriteRule, but you can capture paramters via RewriteCond and use it (with %) in RewriteRule:

RewriteCond %{QUERY_STRING} a=0&b=(.*) RewriteRule ^news.php /specialnews/%1? [R=301]

更多推荐

本文发布于:2023-04-12 21:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c8945b3547b8ef24f99c880b4c641441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   密钥   到新   URL   RewriteRule

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!