I have searched stackoverflow for whole day, found code only working for redirecting Desktop ->Mobile, sometimes it works, sometimes it not:
RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos" [NC]
RewriteRule ^$ https://www.example.com/m/ [L,R=302]
Anyway, i can not find any working solution for redirecting Mobile -> Desktop.
Can anybody share working solution of .htaccess for redirection https://www.example.com
—> https://www.example.com/m/
for Mobile devices and https://www.example.com/m/
—> https://www.example.com/
for Desktop users.
Thanks.
2
Answers
I just figured out the problem. Found that Cloudflare has mobile redirect option by itself. So made a mobile site on subdomain, enabled mobile redirect on CF to that subdomain. Enabled “Cache everything” on both root domain and subdomain. Removed redirect rules from .htaccess. Now i have normal TTFB and mobile traffic redirection is working. Only Desktop->Mobile - will be good as is it.
You can try these 2 redirect rules for mobile -> desktop redirection: