I had a site on domiy.com and now I'm changing the name to namedar.com. I'd like to 301 redirect all requests for domiy.com (or nametyper.com) so that they return namedar.com with the request URI intact.
I've tried simply redirecting everything to namedar.com but that leads to a redirect loop when a request arrives for namedar.com.
rewrite ^ $scheme://nametyper.com$request_uri permanent; # Doesn't work
I'd also like to keep the configuration set up in such a way that all 'www' requests are redirected to the non-www version.
My nginx.conf
looks like this at the moment:
server {
server_name namedar.com www.namedar.com domiy.com www.domiy.com nametyper.com www.nametyper.com;
# Remove all 'www.' prefixes.
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ $scheme://$host_without_www$1 permanent;
}
}
How do I write a rewrite
directive in order to accomplish this?