Last active
August 29, 2015 14:05
-
-
Save hbehkamal/1a477782b3e2627d7cc2 to your computer and use it in GitHub Desktop.
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
# Number 1 | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} !^m\. [NC] | |
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera\smobile|palmos|webos) [NC] | |
RewriteRule ^ http://m.tejanik.com%{REQUEST_URI} [L,R=301] | |
</IfModule> | |
# Number 2 | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC] | |
RewriteRule ^$ http://m.example.com/ [L,R=302] | |
</IfModule> | |
# Number 3 | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteBase / | |
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$) | |
RewriteRule ^ - [CO=mredir:0:www.website.com] | |
RewriteCond %{HTTP:x-wap-profile} !^$ [OR] | |
RewriteCond %{HTTP:Profile} !^$ [OR] | |
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR] | |
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC] | |
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC] | |
RewriteCond %{HTTP_HOST} !^m\. | |
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) | |
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC] | |
RewriteRule ^ http://m.website.com [R,L] | |
</IfModule> | |
# Number 4 | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
# Check if this is the noredirect query string | |
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$) | |
# Set a cookie, and skip the next rule | |
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S] | |
# Check if this looks like a mobile device | |
# (You could add another [OR] to the second one and add in what you | |
# had to check, but I believe most mobile devices should send at | |
# least one of these headers) | |
RewriteCond %{HTTP:x-wap-profile} !^$ [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} !\smredir=0(;|$) | |
# Now redirect to the mobile site | |
RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment