How to permanently remove ?m=1 from URLs in Blogger

Discover how to eliminate the ?m=1 parameter from your Blogger URLs to improve indexing and optimize your blog's performance.

If you have a blogger blog, you might have noticed that every single webpage of your blog gets redirected to url with appended query parameter m=1 when visited on a mobile device. I personally don't like this behaviour of blogger.

According to Blogger, there is no problem with this redirection. But issues like Alternative page with proper canonical tag and Page with redirect for many urls blow up in your Search Console and most of them might be caused due to this redirection.

Why I am telling you issues Alternative page with proper canonical tag and Page with redirect for most of urls, are caused due to this redirection? Let me explain. Suppose Google smartphone crawler crawls a post /2025/01/post.html found in /sitemap.xml, it gets redirected to /2025/01/post.html?m=1 since it is a smartphone crawler and hence the url /2025/01/post.html is marked as Page with redirect. Because the crawler was redirected to /2025/01/post.html?m=1, it will now crawl it, then it finds that current url /2025/01/post.html?m=1 is an alternate page since the page has defined /2025/01/post.html as its canonical url through rel=canonical and hence /2025/01/post.html?m=1 is marked as Alternative page with proper canonical tag. Your post will likely be indexed on Google when the desktop crawler processes the canonical URL (/2025/01/post.html), the desktop crawler does not encounter the ?m=1 redirection and directly considers the desktop version for indexing.

Many of you asked me a lot of times about getting rid of m=1 redirection. Currently there is no native way from Blogger to stop this behaviour, but I have few workarounds which prevents the redirection from server side, unlike others which guide you to remove it in client side using Javascript and History API.

  1. Using Workers: By using Cloudflare Workers as middleware, we can modify the response before it reaches to user. What we can do is detect the device type (i.e. mobile, tablet or desktop) using User-Agent request header and fetch the origin by appending m=1 query parameter if the request comes from a mobile or tablet devices and send it back to the user. By doing this, user will no longer get redirected to the url with m parameter when visited on mobile or tablet devices.
  2. Using Rewrite Rule: Similar approach as using Workers but we shall use Cloudflare's Rewrite URL rule instead of Workers to achieve this. This method does not work as expected since the matches operator is not available to free zones, therefore we instead use contains to check if User-Agent contains Mobi or mobi. If yes, rewrite the URL by appending m=1 to query.

This process requires Custom domain proxied to Cloudflare server which means you need a Custom Domain integrated with Cloudflare. Therefore, we can't do the same for .blogspot subdomain.

According to Blogger, they do not support Cloudflare Integration. Therefore you may face unexpected issues if you do so. Don't try it if you don't have technical knowledge. If you still want to try it, try at your own risk, I am not responsible if your site gets offline or things break after doing so.


Requirements

Before we start, there are several things which must be required:

  1. DNS must be managed by Cloudflare.

    Proxy must be enabled.

Using Workers

I have been using this method from years, works as expected. Using Workers, you can even modify the response further i.e. rewriting html using workerd's HTMLRewriter API, modifying response headers, etc. if you have enough knowledge about it.

Limitations

Before we begin, you must be aware about Cloudflare Workers Limits. If you hit these limits, the site will not be accessible. To solve this issue, you may consider switching to Paid plan.

Creating Workers in Cloudflare

We first need to write our logic in a Cloudflare Workers app, which is going to work as a middleware for our Blogger Blog.

  1. Login to your Cloudflare Account.
  2. Go to Workers & Pages section and click on Create application.
  3. Go to Workers tab and click on Create Worker and rename the worker as prevent-m-redirect-blogger.
  4. Click on Deploy as we shall be able to edit code after deploying Hello World! worker.
  5. Now click on Edit code and replace the existing code with the following code:
    /**
     * Environment interface
     * 
     * @typedef Env
     * @property {string} my_var
     */
    
    // constants
    const MOBILE_REGEX = /(?:phone|windows\s+phone|ipod|blackberry|(?:android|bb\d+|meego|silk|googlebot) .+? mobile|palm|windows\s+ce|opera\ mini|avantgo|mobilesafari|docomo|KAIOS)/i;
    const TABLET_REGEX = /(?:ipad|playbook|(?:android|bb\d+|meego|silk)(?! .+? mobile))/i;
    
    /**
     * A helper function to get the device type from user-agent
     * 
     * @param {string | null} userAgent
     * 
     * @returns {"mobile" | "tablet" | "desktop"}
     */
    const getDeviceType = (userAgent) => {
      if (typeof userAgent === "string") {
        if (MOBILE_REGEX.test(userAgent)) {
          return "mobile";
        }
    
        if (TABLET_REGEX.test(userAgent)) {
          return "tablet";
        }
      }
    
      // Everything else not matched above will be considered as desktop
      return "desktop";
    }
    
    /**
     * An object with workers handlers
     * 
     * @type {ExportedHandler<Env>}
     */
    const worker = {
      async fetch(request, env, context) {
        // Get the device type from user-agent header
        const deviceType = getDeviceType(request.headers.get("User-Agent"));
    
        const proxiedUrl = new URL(request.url);
        // Set the search param 'm' with value '1' if the device type is not 'desktop'
        if (deviceType !== "desktop") {
          proxiedUrl.searchParams.set("m", "1")
        }
    
        const proxiedRequest = new Request(proxiedUrl, {
          method: request.method,
          body: request.body,
          headers: request.headers,
          redirect: "follow"
        });
    
        const proxiedResponse = await fetch(proxiedRequest);
    
        const response = new Response(proxiedResponse.body, proxiedResponse);
    
        // OPTIONAL: You can further modify the response here :)
    
        return response;
      }
    }
    
    // Export handlers
    export default worker;
  6. Click on Save and Deploy.

Creating Routes

Now, we need to tell Cloudflare which routes should be served by our newly created worker.

  1. Go to Websites section in Cloudflare Dashboard and select your domain.
  2. Now go to Workers Routes section and then click on Add Route.
  3. Input the fields as shown in the given table:
    Route Service Environment
    www.fineshopdesign.com/* prevent-m-redirect-blogger production
    *Input the fields as per your blog url and workers name.

    You can route multiple subdomains which are hosted on Blogger to the same worker in order to prevent the m=1 redirection.

Using Rewrite Rule

This method does not work as expected since it considers a request as mobile if the User-Agent header contains Mobi or mobi unlike Workers where we use regular expressions to check if User-Agent device type is mobile, tablet or desktop. Therefore it may still do ?m=1 redirection in cases where User-Agent header does not contain any of Mobi or mobi.

  1. Go to Websites section in Cloudflare Dashboard and select your domain.
  2. Now go to Rules > Overview section.
  3. Next to URL Rewrite Rules, select Create rule.
  4. Name the rule, i.e. Rewrite Blogger Mobile URLs.
  5. Under If incoming requests match…, select Custom filter expression.
  6. Click on Edit Expression and paste the following in the field and replace blog url with yours:
    http.request.full_uri wildcard "http*://www.fineshopdesign.com/*" and
    (http.user_agent contains "mobi" or http.user_agent contains "Mobi")
  7. Under Path, select Preserve.
  8. Under Query, select Rewrite to..., switch from Static to Dynamic and paste the following in the field:
    wildcard_replace(http.request.uri.query, "*", "${1}&m=1")
  9. Click on Deploy.

Conclusion

While the methods discussed above do not entirely eliminate search console errors such as Alternative page with proper canonical tag or Page with redirect, they can significantly reduce their occurrence by preventing the unnecessary ?m=1 redirection for mobile and tablet devices. Implementing these solutions may improve your blog's indexing and overall performance, but it is essential to carefully follow the steps and be aware of the limitations and risks involved, especially when integrating with Cloudflare. Ultimately, these workarounds provide more control over how your Blogger URLs are handled, enhancing your blog's optimization efforts.

Copyright (c):
fineshopdesign.com

About the author

Deø Kumar
Lost in the echoes of another realm.

7 comments

  1. Admin
    Admin
    please help me to fix this problem after i add this code to my website it show link in desktop www.exemple.com/?m=0
    1. Deø Kumar
      Deø Kumar
      I have been using the same code for more than a year and I never faced such issue. I need more information in order to get it fixed.
    2. DESLAB
      DESLAB
      I also had the problem that after using the code, ?m=0 was added in the desktop
    3. DESLAB
      DESLAB
      remove return "desktop"; will fix it
    4. Deø Kumar
      Deø Kumar
      If you see ?m=0 after only opening a post url from homepage, it is probably the link itself containing the ?m=0 in its href attribute.
    5. Admin
      Admin
      this issue happen too on your website when click on certain labels in right sidebar
    6. Deø Kumar
      Deø Kumar
      The issue is resolved and the post is updated, update your workers code.
To avoid SPAM, all comments will be moderated before being displayed.