A few days ago I've received an email from someone regarding
my earlier post on Nginx subdomain rewrites with some questions on rewriting to a different domain. For example each request on subdomain.domain1.com to be forwarded as a request to subdomain.domain2.com.
The rewrite module wasn't meant for such requests, just having a string starting with "http://" will trigger a redirection. The problem can be solved however, by proxying the request to the appropriate domain:
location / {
if ($host ~* "^(.+)\.domain1\.com$") {
proxy_pass http://$1.domain2.com;
}
proxy_redirect off;
# Some other code..
}