移动重定向使用htaccess的桌面版本 [英] Mobile Redirect to desktop version using htaccess

查看:239
本文介绍了移动重定向使用htaccess的桌面版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站名为

www.example.com

我有一个名为移动网站

I have a mobile website called

m.example.com

首先,我想从桌面版自动重定向到移动网站(如果它是移动只..我想检测到所有的移动版本)

firstly i want to redirect automatically from desktop version to mobile site (if it is mobile only.. i want to detect all mobile versions)

那么我想用一个htaccess自动主要网站的网址重定向到移动版本.. 然而,有指回主站要求移动版链接

then I want to use an htaccess to automatically redirect the main website URL to the mobile version.. However, there is a link on the mobile version that points back to the main website called

www.example.com/?nm=1 纳米的意思是 nomobile

我想设置cookie的这一个.. (重定向到来自移动网站网页版)

i want to set cookie for this one.. (redirect to desktop site from mobile site)

如果用户通过前段时间之后再来..我要检查高压饼干.. (检查www.example.com/?nm=1设置cookie的前面)如果还没有的cookie自动重定向到移动版本......如果有饼干想留在桌面版本。

if user come again after passing time ago.. i want to check hv cookie.. (check www.example.com/?nm=1 set cookie earlier) if havent cookie automatically redirect to mobile version... if have cookie want to stay in desktop version.

我怎样才能做到这一点通过的htaccess 没有JavaScript。

How can I accomplish this via htaccess without JavaSCript.

推荐答案

这个答案解决了部分问题为您。就这样的回答,我不会建议使用用户代理为你的清单。找到一个名单,是适合你的,把它放在规则。移动设备的类型,浏览器在移动设备等是不断变化的,而这个答案会过时之前,我甚至贴吧。你需要适应这个规则有点prevent它匹配如果cookienomobile设置为1。你需要在URL中看到了纳米= 1,设置cookie的规则。你可能还需要某种形式的重置为oookie,我贴上纳米= 0。

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]

请检查的文档,饼干了解正确的使用方法对您的特定网站上的CO-标志。在code以上没有进行测试,但在理论上它应该工作。

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.

这篇关于移动重定向使用htaccess的桌面版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆