简体   繁体   中英

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

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...

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 ).

I want to add a solution on NginX:

Use below code in "location /" Of VirtualHost config

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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