RewriteEngine on # Check if this is the desktop to mobile query string RewriteCond %{QUERY_STRING} (^|&)m=1(&|$) # Set a cookie, and skip the next 2 rules RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=2] # Check if this is the mobile to desktop query string RewriteCond %{QUERY_STRING} (^|&)m=0(&|$) # Set a cookie, and skip the next rule RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S] RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] # Check if we're not already on the mobile site RewriteCond %{HTTP_HOST} !^m\. # Can not read and write cookie in same request, must duplicate condition RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) # Check to make sure we haven't set the cookie before RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC] RewriteRule ^(.*)$ http:
2.) this cannot be done with mod_rewrite, except that "/ chairs" is an existing file (and, I think, it is not). So I would test it with your desired scripting language - for example. in php:
if (!pageexists($_GET['page']) && $_SERVER['HTTP_HOST'] == 'm.website.com') header("Location: http://m.website.com/");
where pageexists () is the function that you define to check if there is content for this page in the mobile version.
source share