Problems met when using Cloudflare Mobile Redirect on MediaWiki sites

tl;dr: the __cf_mob_redir is correctly set, but only in effect when revisiting the desktop view twice.

Recently I’ve been trying to let Cloudflare cope with my MediaWiki site. I do know that there isn’t much documentation and it seems like a bad reputation on MediaWiki + Cloudflare, but I’ve been solved most of the problem.

The only problem I met is the mobile frontend. According to the manual on MediaWiki.org, it DOES redirect the visitors to mobile views correctly, but then they can’t switch back to the original view. After searching the whole supporting center, I get to know that Cloudflare detects a Cookie __cf_mob_redir to determine whether to switch back to the desktop view.

I managed to let Mobile Frontend use that cookie to determine whether to use mobile view, and when testing the cookie is set correctly. Later I test it out on a real phone, things get wrong. I clicked the “Desktop view” link in the buttom, but I was still on the mobile view. Really disappointed, I clicked the link again and miracle happens! Now I’m really on the desktop view.

I tried Chrome devtools to simulate a mobile device. When the desktop link is clicked the first time, the cookie is correctly set (both value and domain), but it’s not redirected to the desktop view. The second time it’s redirected to the desktop view, cookies unchanged.

I’m curious on why this would happen and I’d like to know what could be the problem.

I don’t think you need Mobile Redirect. The site is responsive and switches to a mobile layout on a narrow screen.

It does, but Mobile frontend provides a more mobile friendly view. (e.g. Mobile Visual Editor; on normal view the Visual Editor works awfully.)

Solved by using the HTTP Response Header Modification function provided by Cloudflare.

Well, doesn’t seems to work now. nvm, I’ll just go with no cache to restrain from the headache.