Nello Sorrentino
Nello Sorrentino

Reputation: 41

htaccess mobile redirect issues

How can I redirect mobile users to /mobile/ directory?

This code work for me only if users start navigate from main path (http://www.mywebsite.it) but if they click on a link on facebook (http://www.mywebsite.it/news/title-news/123.html) they reach the non-mobile version...

RewriteCond %{HTTP_USER_AGENT} blablabla [NC]
RewriteRule ^$ http://www.mywebsite.it/mobile [R=302,L]

If I change the second line width this one:

RewriteRule ^ http://www.mywebsite.it/mobile [R=302,L]

the redirection is ok but the mobile version of website is inaccessible (images not displaying, jquery mobile doesn't work...)

Who can help me?

----|----

And if I want to exclude a subfolder? My back-end is responsive but now it is impossible to access at http://www.mywebsite.it/admin because .htaccess redirect to mobile version!

Upvotes: 1

Views: 68

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

You have to exclude your existent files from the rule :

#--exclude existent files--#
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]        RewriteCond %{HTTP_USER_AGENT} blablabla [NC]
RewriteRule ^(.*)$ http://www.mywebsite.it/mobile/$1 [R=302,L]

Otherwise the Rule redirects them to the mobile directory.

Upvotes: 1

Related Questions