使用htaccess重定向仅限WAP的手机?

时间:2015-01-13 14:47:15

标签: android iphone .htaccess redirect wap

我遇到了问题。在reading all of this post之后,我正在尝试仅为不支持现代浏览器功能的WAP设备实施重定向。

例如,我希望旧的BlackBerry使用此重定向,但不能使用Android或iPhone设备。

RewriteEngine On

RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$

RewriteCond %{REQUEST_URI}          !^/wap/?$
RewriteRule ^ http://example.com/wap/ [R,L]

问题是此规则会重定向所有移动设备。我还能说出现代浏览器吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

这将在我的wordpress网站上用于重定向到我的移动网站m.mysite.com

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



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] 

如果需要,您可能需要修改某些部分。