Advanced HTACCESS Subdomain Redirection (foo.dom2.com to foo.dom1.com) Advanced HTACCESS Subdomain Redirection (foo.dom2.com to foo.dom1.com) wordpress wordpress

Advanced HTACCESS Subdomain Redirection (foo.dom2.com to foo.dom1.com)


You're on the right track with %{HTTP_HOST} but you need to use backreferences (%1, %2, etc) to access the match against it. You want to do something like this:

RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain2\.com$ [NC]RewriteRule ^(.*)$ http://%2.domain1.com/$1  [L,R]

Note that if you try to access: http://www.sub.domain2.com/foo it will redirect you to http://sub.domain1.com/foo, The "www." of the original request is gone. If you want the www, change the rule to:

RewriteRule ^(.*)$ http://%1%2.domain1.com/$1  [L,R]