removing just “?m=1” from url using rewrite rule

余生长醉 提交于 2019-12-13 04:14:03

问题


just few day before i had migrated my blogger blog to wordpress. Now i find crawn error with many url, at the end of many url the name and value is there (?m=1) which shown as a 404 error now i want to redirect all the url additing .htaccess file example:

http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html?m=1

musy redirect to

http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html

any one is having expertise in url rewrite kindly help me...


回答1:


I haven't got a test system handy, but something like this in your .htaccess should do the trick:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule ^(.*)$ /$1? [R=301,L]

If memory serves, you need the ? at the end of the target in the RewriteRule to stop the original query string being appended.

The code assumes you haven't got any other parameters (eg it won't work if you have ?m=1&foo=bar).




回答2:


I want to add a solution on NginX:

Use below code in "location /" Of VirtualHost config

if ($query_string ~ "^m=1$"){
  rewrite ^(.*)$ /$1? redirect;
}


来源:https://stackoverflow.com/questions/18940522/removing-just-m-1-from-url-using-rewrite-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!