Reputation: 9264
I want to redirect users on a mobile device to a specific landingpage (not a folder). But it supposed to be only a landingpage. So the user must be able to navigate on the website. I did a lot of research and customized this approach. Unfortunately it is still not working for mobile devices. The page doesn't even load on my phone.
# 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]
Can anyone help me out? Thank you so much! I really appreciate it.
Upvotes: 1
Views: 392
Reputation: 9264
Finally got it!
# 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]
Upvotes: 1