Martin Boynton
Martin Boynton

Reputation: 125

htaccess redirect working to mobile, but not to desktop

Mobile devices redirect to domain/m/request_uri, but if you put that URL in desktop, it should redirect to domain/request_uri.

Any suggestions? Thanks!

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(fb/)?(takeaction|\d{1,3})/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/$1 [L,R=302]

RewriteCond %{REQUEST_URI} ^/m/(takeaction|\d{1,3})/.*$
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile)" [NC]
RewriteRule ^/m/(.*)$ /$1 [L,R=302]

Upvotes: 0

Views: 886

Answers (1)

Jon Lin
Jon Lin

Reputation: 143956

It's just not redirecting at all. I've managed to get this to redirect to root, so the RewriteCond line seems to work, but I think my problem is with RewriteRule not changing "domain.com/m/request" to "domain.com/request"

Try removing the leading slash in your rewrite rule from:

RewriteRule ^/m/(.*)$ /$1 [L,R=302]

to:

RewriteRule ^m/(.*)$ /$1 [L,R=302]

Leading slashes are removed from the URI when used to match against the RewriteRule directive when they are used in an htaccess file.

Upvotes: 1

Related Questions