Is it possible to create a page rule that circumvents Cloudflare's mobile redirect

Hi,
I submitted a support ticket for this question, but on a Cloudflare “Free” plan, there is little support for me via a ticket. It was suggested posting the issue on the community forums. Here I am. :upside_down_face:

Can you (can I) create a page rule that circumvents Cloudflare’s “mobile redirect”?

“Mobile redirect” is a terrific feature to use in lieu of .htaccess redirection. With it enabled for my domain, I wonder if a page could be excepted from being redirected, and instead send users (on mobile devices) on to a different location.

The normal “mobile redirect” route goes from all pages on the domain, w3.domain.com, to this page: m.domain.com.

However, if a mobile user visits downlink.php on the domain, for example, could the user then be forwarded from w3.domain.com/downlink.php to w3.domain2.com/downlink.php?

Maybe a page rule could achieve this, but I don’t know whether Cloudflare page rules are capable of overriding “mobile redirect” for one page.

Or, alternatively, could I use an .htaccess directive on my origin server that overrides “mobile redirect” for downlink.php?

The knowledge base does not contain an article, or articles, that cover this topic.

I would appreciate any advice or help you (community members) are able to offer. Thanks in advance.

Tom

Making your site a responsive design and doing away with the mobile redirect is one fix (if perhaps a bit impractical as a quick fix).

From my testing, Page Rules do not trigger before Mobile Redirect, so that will not work.

If you are able to have the client send a “__cf_mob_redir=1” cookie, then the mobile redirect will not take place, so you could do some testing to see if setting that cookie for just the /download.php path is enough.

1 Like

Hi. Thanks for your reply. It answers whether “mobile redirect” has priority over page rules. Apparently, yes.

On fixing the redirection some other way, perhaps – a symlink or .htaccess come to mind, although .htaccess is a bit uncertain, because it may not override “mobile redirect” – I would like to add that download.php is the landing page after a Paypal transaction. Paypal sends you there after you buy something. Unfortunately, it can only do one landing page, domain A. If a customer makes a purchase on domain B, which is responsive, from a cell phone, Paypal sends the customer to download.php on domain A. Cloudfare “mobile redirect” diverts domain A to m.domain.com.

Would it be a good idea to even consider adding an .htaccess 301 redirect rule on top of “mobile redirect”? Two redirects by definition is a thing to be shunned. On the other hand, Cloudflare “mobile redirect” is not on the server. Does it count as redirection the same way as .htaccess rules?

Newbie question: Is it possible to configure the cookie?

This post was flagged by the community and is temporarily hidden.

Domain A and Domain B are mobile-friendly (responsive). But since iOS iPad and some Android tablets prefer desktop versions, I redirect (Cloudflare redirects) Domain A to m.domain.com, and m.domain.com is an interim page, where end-users can decide to go to the ‘primarily’ desktop site Domain A, or the phone site, Domain B.

I don’t think, setting “__cf_mob_redir=1” works for a single page only. Maybe I err.

I have been mulling this over for several hours today. It seems to me the solution is preempting Cloudflare. Somehow I need to send the client browser to Domain B before “mobile redirect”.

Paypal returns a customer who made a purchase to downlink.php located on Domain A, from where “mobile redirect” sends the user to m.domain.com. Thus downlink.php should have a redirect to Domain B for mobile devices.

To seamlessly move to the mobile version requires duplicating Cloudflare.

Browsers from the following mobile devices are redirected to the mobile-optimized subdomain:

  • iPhone
  • Android
  • iPod
  • Blackberry
  • Palm
  • Mobile
  • Windows CE
  • Opera mini
  • AvantGo
  • Docomo

The iPad and Android tablet user agents will not match and trigger the mobile redirect feature.

My PHP code should include a detection script that is as close as possible to “mobile redirect”, i.e.: it will find the same mobile user agents and ‘ideally’, it would not match iPad and Android tablet.

Is it possible to obtain Cloudflare’s “mobile redirect” source code to deploy the function?

It can’t hurt to ask.

I vote for this solution too :+1:

I am afraid not, if not already available some kind of it on GitHub, if so.

Furthermore, how about using the PHP code from below to achieve what you need at the origin host / server?:

Therefore, if you make it work at the origin host, how about using below:

Hi.
We’re on the same page. I’m heading in that direction, because I don’t think it likely that Cloudflare will publish its sources any time soon.

Mobile_Detect.php includes many callable methods. isiPad(), and to list a few tablets:

 * @method bool isNexusTablet()
 * @method bool isGoogleTablet()
 * @method bool isSamsungTablet()
 * @method bool isKindle()
 * @method bool isSurfaceTablet()
 * @method bool isHPTablet()
 * @method bool isAsusTablet()
 * @method bool isBlackBerryTablet()
 * @method bool isHTCtablet()
 * @method bool isMotorolaTablet()
 * @method bool isNookTablet()
 * @method bool isAcerTablet()
 * @method bool isToshibaTablet()
 * @method bool isLGTablet()
 * @method bool isFujitsuTablet()
 * @method bool isPrestigioTablet()
 * @method bool isLenovoTablet()

There’s a great deal there. The only catches are, DoCoMo’s user agent is strangely absent, as is isAndroidTablet(). I suppose a workaround is checking for isAndroid(), and then run through all the tablets, a long list.

A recent issue also reports: > Issue description

Using Chrome browser on iOS (iPhone and iPad) in Desktop Mode is detected as mobile.

Cloudflare claims that “mobile redirect” singles out iPads and Android tablets, but does it detect when the user switches to desktop view? Probably not, because regardless iPads and Android tablets will be not redirected. So claims the “mobile redirect” support page. Still, it would be interesting to compare Cloudflare’s code with Mobile_Detect.php.

The proposed fix for the issue on Github is below:

Following Changes would fix the issue (based on version 2.8.37)

Line 722:
Original: |CriOS|
Fixed: |CriOS.*Mobile|

Line 727:
Original: \bEdgiOS\b|
Fixed: EdgiOS.*Mobile|

Line 729:
Original: |FxiOS
Fixed: |FxiOS.*Mobile

On a iPhone you will be detected as mobile. If you change to destop mode you will be detected as a computer (and not longer as a mobile device)
Based on documentation of Firefox, Chrome and Edge you will have "Mobile" for Phones inside the UA string.

These are among the reasons I’ve been mulling it over for a couple of hours.

It is a good suggestion by you, and I’m ticking it as the ‘Solution’, since I really doubt that Cloudflare will release source code.

1 Like

Domains A and B are responsive. I still use redirection to Domain B for mobiles, because I trust Cloudflare’s “mobile redirect” to be accurate. I know for a fact that iPads like to consider themselves desktops. It would be wrong to deal with them by merely being responsive. I hope you understand.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.