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.
- 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
ordesktop
) usingUser-Agent
request header and fetch the origin by appendingm=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 withm
parameter when visited on mobile or tablet devices. - 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 usecontains
to check ifUser-Agent
containsMobi
ormobi
. If yes, rewrite the URL by appendingm=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:
-
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.
- Login to your Cloudflare Account.
- Go to Workers & Pages section and click on Create application.
- Go to Workers tab and click on Create Worker and rename the worker as
prevent-m-redirect-blogger
. - Click on Deploy as we shall be able to edit code after deploying Hello World! worker.
-
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;
- Click on Save and Deploy.
Creating Routes
Now, we need to tell Cloudflare which routes should be served by our newly created worker.
- Go to Websites section in Cloudflare Dashboard and select your domain.
- Now go to Workers Routes section and then click on Add Route.
-
Input the fields as shown in the given table:
Route Service Environment www.fineshopdesign.com/*
prevent-m-redirect-blogger
production
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
.
- Go to Websites section in Cloudflare Dashboard and select your domain.
- Now go to Rules > Overview section.
- Next to URL Rewrite Rules, select Create rule.
- Name the rule, i.e.
Rewrite Blogger Mobile URLs
. - Under If incoming requests match…, select Custom filter expression.
-
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")
- Under Path, select Preserve.
-
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")
- 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