Created
September 1, 2016 03:37
-
-
Save yudaprawira/875e7a05c65aaa5dd9c76d4ed94bbe77 to your computer and use it in GitHub Desktop.
redirect www to mobile site using htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if mobile=1 is set and set cookie 'mobile' equal to 1 | |
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$) | |
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}] | |
# Check if mobile=0 is set and set cookie 'mobile' equal to 0 | |
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) | |
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}] | |
# cookie can't be set and read in the same request so check | |
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) | |
RewriteRule ^ - [S=1] | |
# Check if this looks like a mobile device | |
RewriteCond %{HTTP:x-wap-profile} !^$ [OR] | |
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|BlackBerry|RIM BlackBerry|BlackBerry OS|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR] | |
RewriteCond %{HTTP:Profile} !^$ | |
# Check if we're not already on the mobile site | |
RewriteCond %{HTTP_HOST} !^m\. | |
# Check to make sure we haven't set the cookie before | |
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$) | |
# Now redirect to the mobile site | |
RewriteRule ^ https://m.juara.in%{REQUEST_URI} [R,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment