简体   繁体   English

使用RewriteRule进行重定向,将密钥重定向到新的URL

[英]Redirect with RewriteRule keeping keys redirected to the new url

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. 因此,a = 0表示特殊新闻。 So I need redirect only those urls, that have a=0 and base url ( news.php ) also to /specialnews/ . 因此,我只需要将具有a = 0和基本URL( news.php )的那些URL也重定向到/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. 没有帮助;)需要指导。

You can't match query string params in RewriteRule, but you can capture paramters via RewriteCond and use it (with %) in RewriteRule: 您无法在RewriteRule中匹配查询字符串参数,但是可以通过RewriteCond捕获参数,并在RewriteRule中使用它(与%配合使用):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM