.htaccess移动设备重定向到子文件夹和桌面视图按钮 [英] .htaccess mobile redirect to subfolder and desktop view button

查看:59
本文介绍了.htaccess移动设备重定向到子文件夹和桌面视图按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下内容的.htaccess文件:

I have a .htaccess file with the following:

RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

一切都很好,并且在用手机查看时效果很好-它可以检测并直接进入移动站点所在的子文件夹.但是我想弄清楚的是如何在移动网站的底部提供一个链接,该链接将允许用户查看桌面版本.当他们使用台式机版本时,我希望他们能够重新使用移动设备...

Everything is fine and works great when viewing form a mobile phone - it detects and goes straight to the subfolder where the mobile site is located. But what I am trying to figure out is how to have a link at the bottom of the mobile site that will allow the user to view a desktop version. And when they're on the desktop version I want them to be able to get back to mobile...

有人可以帮我吗?

推荐答案

我不会使用cookie,因为这对于首次访问者或cookie设置为禁用的用户可能无法正常使用.我将添加一个预定义的GET参数,以强制网站转到非移动版本.

I wouldn't use cookies since that might not work properly for first-time visitors or users with cookies set to disabled. I would add a pre-defined GET-parameter that forces the site to go to the non-mobile version.

一个示例:如果您的域名是www.fancysite.com,则可能是www.fancysite.com/nomobile.对于"nomobile" URL,您可以在.htaccess中定义自动转发.为此重写规则使用[L]条件,以便忽略其他条件.如果不存在"nomobile"字符串,则您的(已经工作的)用户代理检测会启动,并且用户会到达移动站点.

One example: If your domain is www.fancysite.com that could be www.fancysite.com/nomobile. For the "nomobile" URL you define an automatic forwarding in the .htaccess. Use the [L] condition for this rewrite rule so that other conditions are ignored. If the "nomobile" string is not present, your (already working) user agent detection kicks in and the user reaches the mobile site.

请参阅以下详细信息(尤其是在条件"下):

See these for some details (especially under "conditions"):

http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/

http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/

这篇关于.htaccess移动设备重定向到子文件夹和桌面视图按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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