How do I redirect URL parameter ?m=1?

I recently switched from blogger to wordpress and noticed that many incoming links have added a ?m=1 parameter to the end of my post link.

Example:

Read More
http://www.example.com/2015/06/name-of-blog-post.html?m=1 

I have searched for a way to take out the ?m=1 parameter and I found a similar situation to mine on this site but the person also had an issue with some links missing .html.

As far as I know, all of my links have .html added on so I don’t know that his code would work.

What would be the easiest and best way for me to fix this?

Related posts

2 comments

  1. You can’t change the incoming links – those are set by the href tag on the page that a user clicks.

    It doesn’t affect what’s on the page unless your page uses that variable, for example in PHP via $_GET:

    $data = $_GET["m"];
    print $data; //will output "1"
    

    It is usually used in this sense to see where the referrals are coming from – Facebook will append ?ref=ts to the end of outgoing links to show that it was clicked from the “Top Search” for example.

  2. To simply remove the query string entirely when ?m=1 (exactly) is passed as a URL parameter, then you can do something like this in your root .htaccess file using mod_rewrite. The following directives should be put at the top of your .htaccess file:

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

    Change the 302 (temporary) to 301 (permanent) when you are sure it’s working OK. Since permanent redirects are cached by the browser they are not good for testing.

    However, if this is simply to resolve a canonicalisation issue (to control the URL that search engines are indexing) then you could simply use a rel="canonical" element in your head section instead.

    Also, in Google Search Console (formerly Google Webmaster Tools) you can instruct Google to ignore the m URL parameter. Although this obviously only affects Google.


    If you need to match ?m=1 or ?m=0 then you can change the CondPattern from ^m=1$ to ^m=[01]$.

Comments are closed.