ใช้ $_SERVER[‘HTTP_USER_AGENT’] ครับ ตรวจสอบ Web Browser
<?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/iPhone|Android|Blackberry/i', $agent)){ header("location:http://m.cymiz.com"); exit; } ?>
เขียนที่ .htaccess ง่ายกกว่า
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]
อีกวิธี
RewriteEngine On # Check if this is the noredirect query string RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$) # Set a cookie, and skip the next rule RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S] # Check if this looks like a mobile device # (You could add another [OR] to the second one and add in what you # had to check, but I believe most mobile devices should send at # least one of these headers) RewriteCond %{HTTP:x-wap-profile} !^$ [OR] RewriteCond %{HTTP:Profile} !^$ # Check if we're not already on the mobile site RewriteCond %{HTTP_HOST} !^m\. # Check to make sure we haven't set the cookie before RewriteCond %{HTTP:Cookie} !\smredir=0(;|$) # Now redirect to the mobile site RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]
อีกตัว
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Options +FollowSymlinks RewriteEngine on RewriteBase / # prevent looping RewriteCond %{HTTP_HOST} !^m.mysite.com$ # if the browser accepts these mime-types, it's definitely mobile, or pretending to be RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR] # a bunch of user agent tests RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR] RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR] RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR] RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC] # rewrite rules here RewriteRule ^(.+)\$ http://m.mysite.com/$1 [R=302,NC]
ใช้ jQuery Mobile Framework ง่ายกกว่าครับ
องรับหลาย OS มาก