仅将移动设备重定向到目标网页。但只有一次

时间:2015-03-31 12:15:12

标签: .htaccess redirect

我想将移动设备上的用户重定向到特定的目标网页(而不是文件夹)。但它应该只是一个登陆页面。因此用户必须能够在网站上导航。我做了很多研究和定制的this方法。不幸的是,它仍然无法用于移动设备。该页面甚至无法加载到我的手机上。

# 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 to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\smredir=0(;|$)

# Now redirect to the mobile site
RewriteRule ^ http://example.com/mobilelandingpage [R,L]


# Set cookie for mobile devices to make sure they will not get redirect to the landingpage again
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S]

任何人都可以帮助我吗?非常感谢!我真的很感激。

1 个答案:

答案 0 :(得分:1)

终于搞定了!

# 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_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Profile}       !^$
RewriteCond %{HTTP:Cookie}        !\smredir=0(;|$)

# Now redirect to the mobile site
RewriteRule ^/?$ http://domain.com/index.php/landingpage.html [L,R=302]


# Set cookie for mobile devices to make sure they will not get redirect to the landingpage again
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile}       !^$
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]