asotshia
asotshia

Reputation: 121

Htaccess does not redirect mobile users to domain.com/m

My page can be accessed through domain.com or www.domain.com
I am trying to have a redirect for users on mobile devices to the domain.com/m or *www.domain.com/m*

However I am having difficulties to do this correctly. I have put this in my .htaccess on index.php of domain.com

How to do this correctly?

RewriteCond %{REQUEST_URI} !^/http://www.domain.com/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

Upvotes: 0

Views: 3168

Answers (4)

Zachary Dahan
Zachary Dahan

Reputation: 1499

Just find that fabulous Website. You got so many possibilities to make a mobile-redirect and they are updated frequently.

http://detectmobilebrowsers.com/

Hope it help you !

Upvotes: 1

freedev
freedev

Reputation: 30227

I did it in this is way:

RewriteCond %{HTTP_USER_AGENT}  (iphone|ipod|android|symbian|windows\ phone|blackberry|iemobile|opera\ mobile|palmos|webos|googlebot-mobile)   [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

and for me, it is working like a charm.

Upvotes: 0

Saul Martínez
Saul Martínez

Reputation: 920

The .htaccess file in HTML5 Mobile Boilerplate actually handles this redirection nicely.

You should take a look either you are working with mobile or not or if you just want to redirect certain UA clients.

Upvotes: 0

qJake
qJake

Reputation: 17139

Try this:

RewriteCond %{HTTP_USER_AGENT} "android" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "ipad" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "iphone" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "ipod" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "iemobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "opera mobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palmos" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "webos" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

Upvotes: 1

Related Questions