开发者

Mobile Redirect via ModReWrite Simple code

is it possible to just use this simple code for the redirection of ALL mobile phones?

RewriteEngine On   
RewriteCond %{HTTP_USER_AGENT} .*(iPad|iPhone|Mobile).* 
RewriteRule .* http://w开发者_运维知识库ebsite.com/ [R]

since Android and Symbian and BB have "Mobile" in their strings.

or should the UserAgents be explicitly listed out like here: http://www.projectronin.com/blog/?p=10

thanks


If possible, redirect based on screen resolution or OS, not specific model of device. Keeping a model-specific list up to date is impossible.

Also, the above solution will always redirect them to the mobile site. Sometimes users want to use the full site on their mobile devices. For that reason, I would handle this in your site's code, not in htaccess.

Put something like this in your front controller, or a controller plug-in -- any bit of code that is executed on every page request in the non-mobile version/module of your site:

if(!isset($session->non_mobile)){ $session->non_mobile = false; }

if($_GET[non-mobile]){ $session->non_mobile = true; }

if(is_mobile_browser() && $session->non_mobile == false))
{
   header('location: http://m.yoursite.com');//redirect to mobile version
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜