使用htaccess的重定向到移动版本,除非用户希望"强制桌面版本和QUOT; [英] Using htaccess to redirect to mobile version unless user wants to "force desktop version"

查看:226
本文介绍了使用htaccess的重定向到移动版本,除非用户希望"强制桌面版本和QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下.htaccess文件重定向到移动版本我的网站:

I have the following .htaccess file to redirect to the mobile version of my site:

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

不过,我需要添加一个条件,为移动用户能够请求桌面版网站。

However, I need to add a condition for mobile users to be able to request the desktop site.

我已经搜索了一下周围,并没有发现一个简单的答案。我只是需要有一个网址,如 http://www.example.com/?desktop 以避免重定向到/移动

I've searched around a bit and haven't found a simple answer. I just need to have an url such as http://www.example.com/?desktop to avoid the redirection to /mobile

推荐答案

试试:

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

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

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