简体   繁体   English

301使用查询字符串重定向URL

[英]301 Redirect for URL's with Query string

I want to do a 301 redirect for all urls with a query string to the base url (without the query string). 我想对所有带有查询字符串的URL进行301重定向到基本url(没有查询字符串)。

For example: 例如:

  1. http://www.mysite.com/directory/abcbd.html?q1=23&q2=89 should be redirected to http://www.mysite.com/directory/abcbd.html http://www.mysite.com/directory/abcbd.html?q1=23&q2=89应该重定向到http://www.mysite.com/directory/abcbd.html

    1. http://www.mysite.com/directorynew/file3.html?q1=213&q2=389&q3=ttim should be redirected to http://www.mysite.com/directorynew/file3.html http://www.mysite.com/directorynew/file3.html?q1=213&q2=389&q3=ttim应该被重定向到http://www.mysite.com/directorynew/file3.html

As shown in the above examples "q1=" will ALWAYS appear in the beginning in the urls in question. 如上面的示例所示,“ q1 =“将始终出现在所讨论的网址的开头。 The next set of urls could vary. 下一组网址可能有所不同。 So is there something like: RewriteCond %{query_string} "q1=.*" - not good at these things! 所以有类似的东西:RewriteCond%{query_string}“ q1 =。*”-这些东西不好!

What entries do I need to enter in the .htaccess file? 我需要在.htaccess文件中输入哪些条目?

Thanks, Sameer 谢谢,Sameer

Actually I got it done using the wp_redirect plugin. 实际上,我是使用wp_redirect插件完成的。

source: /(. )/(. ).html(. )\\?dontneedthisstring=(. ) target: /$1/$2.html 源:/(。 )/(。 html(。 )\\?dontneedthisstring =(。 )目标:/$1/$2.html

This cleans it up. 这样可以清理干净。

Here "dontneedthisstring" was the uniq string i was trying to get rid of. 这里“ dontneedthisstring”是我试图摆脱的唯一字符串。

我会用以下规则做到这一点:

RewriteRule ^(.*)\?.*  $1  [L,R=301]

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

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