0

We have a mobile site that is served using multiple domains. We want to redirect users who are using desktop user agents to our desktop sites while preserving the original domain the user used to access the site.

There seem to be a few .htaccess variables that can provide the domain but they include the subdomain as well. My current code is:

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

This works fine, but we want to be able to adjust the domain to be the domain the request rather using than a static domain (example.com).

Is there a way to accomplish this with .htaccess? Thanks!

1 Answers1

0

Yes, you can use RewriteCond to match any part of the domain you want in %{HTTP_HOST} and then reference it in your RewriteRule by using a %1 backreference (%# refers to matched items in parenthesis in the most-recently matched RewriteCond directive).

g491
  • 973
  • 5
  • 7