我正在尝试提供一个htaccess代码,该代码允许我将所有移动设备上的用户重定向到以www.example.com/blog
或example.com/blog
开头的网页到特定网页 - 几乎相同的链接具有以下扩展名:/mobile
。
以便移动设备的网站成为:
www.example.com/blog -> www.example.com/blog/mobile
example.com/blog -> example.com/blog/mobile
我该怎么做?
答案 0 :(得分:1)
您可以将此规则放在您的网站根目录.htaccess:
RewriteEngine On
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$
RewriteRule ^blog/?$ /$0/mobile [L,NC,R=302]
假设您在.htaccess
目录中没有blog/
。
如果您已有blog/.htaccess
,请在blog/.htaccess
RewriteEngine On
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$
RewriteRule ^/?$ /blog/mobile [L,R=302]
如果以上标题不起作用,请使用基于user agent
的检查:
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
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]
RewriteRule ^blog/?$ /$0/mobile [L,NC,R=302]