.htaccess切换移动en桌面视图?

时间:2012-01-12 18:54:15

标签: .htaccess mobile redirect rewrite

我有以下htaccess文件。这将在检测到移动设备时将用户重定向到m.website.com。但是,当人们访问m.website.com上的移动网站时,他们可以选择切换到桌面视图(如果他们愿意)。当他们点击桌面视图时,他们将被发送到www.website.com(此时将它们发送回m.website.com)但在这种情况下我想将它们保存在原始网站www.website.com 。 COOKIE有没有办法,如果满足某个条件,它们将被保存在桌面网站上,如果不满足该条件,将发生重定向?

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]

0 个答案:

没有答案