Mobile Redirect to desktop version using htaccess

后端 未结 1 2031
情书的邮戳
情书的邮戳 2021-01-26 01:07

I have a website called

www.example.com

I have a mobile website called

m.example.com

firstly i want to redire

相关标签:
1条回答
  • 2021-01-26 01:40

    This answer solves part of the problem for you. Just like that answer, I am not going to suggest a list with user-agents for you. Find a list that is suitable for you, and put it in the rule. The types of mobile devices, browsers in mobile devices etc is ever-changing, and this answer would be out-dated before I even posted it. You need to adapt that rule a little to prevent it from matching if the cookie "nomobile" is set to "1". You need a rule that sees the "nm=1" in the url and sets the cookie. You probably also want some kind of reset for that oookie, which I labeled "nm=0".

    RewriteCond %{QUERY_STRING} nm=1
    RewriteRule ^ - [CO=nomobile:1:localhost:10000]
    
    RewriteCond %{QUERY_STRING} nm=0
    RewriteRule ^ - [CO=nomobile:0:localhost:10000]
    
    RewriteCond %{HTTP_USER_AGENT} ^(user-agent1|user-agent2|user-agent3|etc)$
    RewriteCond %{HTTP_HOST} !^m\.example\.com$
    RewriteCond %{HTTP_COOKIE} !nomobile=1
    RewriteRule ^(.*)$ http://m.example.com/$1 [R,L]
    

    Please check the documentation for cookies for the correct usage of the CO-flag on your specific site. The code above is not tested, but in theory it should work.

    0 讨论(0)
提交回复
热议问题