使用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=20What I want - redirect it to
somesite.org/specialnews/20If 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]更多推荐
发布评论