0

I'm trying to redirect from whatever.domain1.com to whatever.domain2.com, but it has to work for any value of 'whatever'. I have tried the following

<VirtualHost <PUBLIC_IP_ADDR>:80>
    ServerName  domain1.com
    ServerAlias *.domain1.com

    RewriteEngine On    
    SetEnvIf Host "(.*).domain1.com" VHOST=$1
    # http replaced with xxxx as otherwise im not allowed to post
    RewriteRule .* xxxx://%{VHOST}.domain2.com [R,L]
</VirtualHost>

however, this does not work, i.e. VHOST variable is always empty. Is there any other way to either manipulate the HTTP Host: header and/or use only a part of it in a redirect?

0

one can use backreferences from RewriteCond regexp match

   ServerName  domain1.com
   ServerAlias *.domain1.com

   RewriteEngine On

   RewriteCond "%{HTTP_HOST}" "^(.*).domain1.com$"
   RewriteRule .* xxxx://%1.domain2.com%{REQUEST_URI}?%{QUERY_STRING} [R,L]

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.