重定向移动设备的特定网址

时间:2018-12-08 12:59:46

标签: .htaccess mobile url-redirection device

第一篇文章;-)

我的问题。一旦移动访问者查看了我网站中的特定网址,我该如何将其重定向到该特定网址的移动版本?

例如,某个移动设备用户访问 mydomain.com/thisurl ,那么该URL仅应针对移动设备用户重定向到 mydomain / thisurl_mobile

我有部分htaccess代码可能是一个开始?但不确定如何针对特定网址执行此操作?这就是我到目前为止(顺便说一句,必须是https):

 <IfModule mod_rewrite.c>
# turn on rewrite engine
RewriteEngine on

# only detect smart phone devices if we are not on mobile site
# to prevent redirect looping
RewriteCond %{QUERY_STRING} !^desktop

# a bunch of smart phone devices
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "windows ce|epoc|opera|mini|nitro" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "j2me|midp-|cldc-|netfront|mot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up\.browser|up\.link|audiovox" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "netfront|mot|up\.browser|up\.link"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "audiovox|blackberry|ericsson,"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|dange"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "alcatel|ericy|vodafone\/|wap1\."[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wap2\.|iPhone|android"[NC,OR]

# redirect google mobile bot
RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile"[NC]

# if the request is from any one of the above devices
# redirect to mobile url
RewriteRule ^$ https://www.mydomain/thisurl_mobile [L,R=302]
</IfModule>

0 个答案:

没有答案