Hello Cloudflare & community.
This is my first post and first of all I want to say one big THANK YOU, for existing, as a service, and giving almost anyone the chance for big big growth.
Recently I’ve spent hours and hours in the Cloudflare’s admin area, and gradually managed to tune up my sites the way they should be.
There’s only one question unanswered, which bothers me - how to, best, redirect Desktop users, if, by chance, they visit the mobile subdomain, that is, https://m.domain.com/request-uri of my site? I want to redirect them back to https://www.domain.com/request-uri.
What I’ve done - I’ve stated in the mobile theme header the canonical url (my site uses Wordpress). Also - I’m using a simple javascript -
<script type="text/javascript">
if (screen.width >= 1024) {
document.location = "https://www.domain.com<?php echo str_replace( home_url(), '', get_permalink($post->ID) ); ?>";
}
</script>
- that is, having in mind, that almost all mobile devices have screen width lesser than 1024 pixels.
Still, some infinite loops occur now and then, although it may be only once an hour or two or so.
I know, that with Enterprise plan one would get separate caching for mobile, tablets and desktop. But yet, that would still not work completely - as here the case is, I wanna redirect all user agents, which are not send via Cloudflare to https://m.domain.com/, yet have visited, back to https://www.domain.com/ , as well as keep the request URI.
I would be very grateful, if you could provide me a sample htaccess directive, I could put before/after the Wordpress rules, and make everything tip-top with my sites. The javascript works like 90% of the time, but seems unprofessional to me and really bothers me and keeps me reading and reading
Thank you in advance, if you’ve got any idea!