Remove ?m=1 Parameter From Blogger URLs Using Cloudflare
A guide to remove the 'm' parameter from Blogger URLs with Cloudflare Workers

How to Remove ?m=1 Permanently from Blogger URLs

Many Blogger users frequently ask how to remove the ‘m’ parameter from their blog’s URL. While this parameter (‘m’1) poses no significant issues, it can be aesthetically unpleasing and redundant. Unfortunately, Blogger doesn’t provide a built-in way to eliminate it, but there is a workaround using Cloudflare Workers. In this guide, we’ll show you how to use Cloudflare Workers as middleware to modify URLs and remove the ‘m’ parameter.

Why Does the ‘m’ Parameter Appear?

The ‘m’ parameter is automatically appended to URLs when a Blogger blog is accessed from mobile or tablet devices. This indicates that the mobile version of the site is being displayed. However, by intercepting and modifying requests using Cloudflare Workers, we can prevent this behavior.


Requirements

Before you begin, you’ll need to meet the following requirements:

  1. Custom Domain:
    • Your blog must use a custom domain, as Cloudflare doesn’t work with .blogspot subdomains.
  2. Cloudflare Account:
    • DNS for your custom domain must be managed by Cloudflare, with Proxy enabled.
  3. SSL/TLS Configuration:
    • Ensure your SSL/TLS is set to “Full (Strict).”
  4. Cloudflare Worker Plan:
    • Note that free-tier Cloudflare Workers come with limitations. Consider upgrading to a paid plan if you hit these limits.

Step-by-Step Guide

1. Configure Cloudflare for Your Domain

  1. Log in to the Cloudflare Dashboard and select your domain.
  2. Go to SSL/TLS Settings:
    • Navigate to SSL/TLS > Configure and select Full (Strict).
  3. Update DNS Proxy:
    • Go to DNS Records and ensure that Proxy Status is set to Proxied (orange cloud).

2. Create a Cloudflare Worker

  1. Log in to your Cloudflare account.
  2. Navigate to Workers & Pages.
  3. Click Create Application > Workers > Create Worker.
  4. Rename the worker to something descriptive, such as remove-m-worker.
  5. Deploy the default “Hello World!” worker, then click Edit Code to replace the default script with the following code:
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;

const getDeviceType = (userAgent) => {
  if (typeof userAgent === "string") {
    if (MOBILE_REGEX.test(userAgent)) return "mobile";
    if (TABLET_REGEX.test(userAgent)) return "tablet";
  }
  return "desktop";
};

const worker = {
  async fetch(request, env, ctx) {
    try {
      const userAgent = request.headers.get("User-Agent");
      const deviceType = getDeviceType(userAgent);

      const url = new URL(request.url);
      if (deviceType !== "desktop") {
        url.searchParams.delete("m");
      }

      const modifiedRequest = new Request(url, {
        method: request.method,
        body: request.body,
        headers: request.headers,
        redirect: "follow",
      });

      const response = await fetch(modifiedRequest);
      return new Response(response.body, response);
    } catch (error) {
      return new Response("An error occurred: " + error.message, { status: 500 });
    }
  },
};

export default worker;
  1. Click Save and Deploy.

3. Set Up Worker Routes

  1. Go to Websites in the Cloudflare dashboard and select your domain.
  2. Navigate to the Workers Routes section and click Add Route.
  3. Input the following details:
    • Route: Use your domain. For example:
      • www.example.com/*
      • blog.example.com/*
    • Worker: Select the worker you just created (remove-m-worker).
  4. Save the route. Now, all requests to your domain will pass through the worker.

Limitations of Cloudflare Workers

  • Free Tier Limits: The free plan offers limited requests per day. If your traffic exceeds these limits, your site may become inaccessible.
  • Custom Domain Required: This method is incompatible with .blogspot domains, as Cloudflare integration requires a custom domain.

Conclusion

By leveraging Cloudflare Workers, you can eliminate the ‘m’ parameter from Blogger URLs without any visible side effects. This method ensures that mobile and tablet users are served the correct version of your site without being redirected to URLs containing the ‘m’ parameter. While this solution isn’t native to Blogger, it’s an effective workaround that enhances the user experience and URL cleanliness for custom domains.

Leave a Reply

Your email address will not be published. Required fields are marked *