I tried following code:-
This code is working fine when user try to access desktop web version from mobile, then this code redirecting user to mobile web version.
RewriteEngine on RewriteCond %{HTTP_USER_AGENT} iphone|ipad|android|blackberry|windows\ phone [NC] RewriteCond %{HTTP_HOST} ^(www)\.example\.com$ RewriteRule ^(.*) http://m.example.com #RewriteRule ^(.*)$ %{HTTP_HOST}/$1
This code is working fine when user try to access mobile web version from desktop, then this code redirecting user to its desktop web version.
RewriteEngine on RewriteCond %{HTTP_USER_AGENT} ^(?:(?!iphone|ipad|android|blackberry|windows\ phone).)*$ RewriteCond %{HTTP_HOST} ^(m)\.example\.com$ RewriteRule ^(.*) http://www.example.com #RewriteRule ^(.*)$ %{HTTP_HOST}/$1
Both the code is working fine if I am using separately, but When I try to use both the code together then I am not getting desired output. Following is the result:
for 1st case: I am getting error of "example.com redirected you too many times."
for 2nd case: working fine.
I want the user to access desktop site only when he is coming from desktop, although when user try to access mobile website from desktop then the user should redirect to its desktop version. and vice versa.