【发布时间】:2012-09-30 05:03:03
【问题描述】:
我首先使用here 描述的方法来创建移动重定向,并且效果很好。
然而,接下来我需要做的是防止它发生在除主页之外的任何页面其他上。换句话说:如果用户从移动设备加载主页,则应该发生重定向 - 但如果他们从移动设备加载任何其他页面,则不应发生重定向。
我希望社区能够就如何有效地实现这一目标提供任何建议。
【问题讨论】:
标签: .htaccess redirect mobile wildcard http-host
我首先使用here 描述的方法来创建移动重定向,并且效果很好。
然而,接下来我需要做的是防止它发生在除主页之外的任何页面其他上。换句话说:如果用户从移动设备加载主页,则应该发生重定向 - 但如果他们从移动设备加载任何其他页面,则不应发生重定向。
我希望社区能够就如何有效地实现这一目标提供任何建议。
【问题讨论】:
标签: .htaccess redirect mobile wildcard http-host
您需要通过签出 User-Agent 来重定向:
Mobile website redirection based on user agent
或在 PHP 上:
<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
//mobile example
if( strpos($useragent,"Blackberry") ) {
header("Location: http://m.nickyeoman.com/");
}
//css example
if( strpos($useragent,"wii") ) { ?>
<link rel="stylesheet" href="/css/wii.css" type="text/css" media="all" />
<php } else { ?>
<link rel="stylesheet" href="/css/global.css" type="text/css" media="all" />
<php } ?>
【讨论】:
我只需要添加
[OR]
RewriteCond %{HTTP_HOST} ^(mydomain\.com|www\.mydomain\.com)$ [NC]
就是这样。所以,最后,它看起来像
# 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] 放入其中。希望我的新手建议有一天能对某人有所帮助
【讨论】: