简体   繁体   中英

Redirect desktop users away from mobile site with .htaccess

Hello Folks at Stackoverflow,

I'm looking to redirect desktop users away from mobile site with .htaccess:

I already have this code which works perfectly when a mobile user tries to access the mobile version of my website example: m.website.com.

RewriteEngine On
RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://m.website.com [L,R=302] 

However if a user types m.website.com on a desktop browser, it goes directly to the mobile version content.

Is there a way to add any additional code to the .htaccess file to make it work in a way that when a desktop user attempts to go to m.website.com it remains in the desktop version.

Place this additional rule in .htaccess of DOCUMENT_ROOT of m.website.com :

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://website.com%{REQUEST_URI} [L,R=302] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM