domain.com and b.domain.com. Both subdomains are on different servers. I'm using nginx as my webserver. What must I change to nginx.conf to redirect all traffic from a.domain.com to b.domain.com?
Thank you!
pjmorse's answer is good (so I upvoted it), but I use a slightly different scheme on a.domain:
server {
server_name a.domain.com c.domain.com d.domain.com; # you can serve any number of redirects from here...
listen 80;
rewrite (.*) http://b.domain.com$1 permanent;
}
This returns a HTTP 301 return code (moved permanently) instead of the 307 that some webservers may return.
This question could stand to provide more details. Can we assume nginx is the httpd on both servers? What kind of configuration is already in place?
This howto gives a hint which leads me to suggest this:
On server a.domain.com
:
server {
listen 80;
server_name a.domain.com;
rewrite ^ http://b.domain.com$request_uri?;
}
On server b.domain.com
:
server {
listen 80;
server_name b.domain.com;
// Remaining vhost configuration
}
server {
server_name
a.domain.com
;
return 301 http://b.domain.com$request_uri;
}
you could set up a permanent redirect from one domain to another.