使用.htaccess的移动设备重定向-仅在首页上 [英] Redirection for Mobile using .htaccess - only on homepage

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

问题描述

我首先使用此处所述的方法创建移动重定向,并且效果很好.

I started by using the method described here in order to create a Mobile redirect, and it works perfectly.

接下来,我要做的是防止它在首页以外的其他任何页面上发生.换句话说:如果用户从移动设备加载主页,则应该进行重定向-但是,如果用户从移动设备加载任何其他页面,则不应进行重定向.

What I need to do next, however, is prevent it from happening on any page other than the homepage. In other words: If the user loads the homepage from a mobile device, the redirect should happen - but if they load any other page from a mobile device, the redirect should not occur.

我希望社区提供有关如何有效完成此操作的任何建议.

I'd love any advice the community might be able to provide as to how to accomplish this effectively.

推荐答案

我只需要添加

[OR]
RewriteCond %{HTTP_HOST}  ^(mydomain\.com|www\.mydomain\.com)$ [NC]

就是这样.所以,最后看起来像

That was it. So, in the end, it looked like

# Check if we're not already on the mobile site AND just going to the homepage
RewriteCond %{HTTP_HOST}    !^m\. [OR]
RewriteCond %{HTTP_HOST}    ^(mydomain\.com|www\.mydomain\.com)$ [NC]
# Can not read and write cookie in same request, must duplicate condition

确保您也将[or]插入那里.希望我的新手建议有一天能对某人有所帮助

Make sure you get the [or] in there too. Hopefully my newb advice will help someone someday

这篇关于使用.htaccess的移动设备重定向-仅在首页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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