Reputation: 542
I want to achieve the following rewrite with nginx:
example.com -> example.io
*.example.com -> *.example.io
So anything that is related to example.com
should be redirected to example.io
, while preserving the subdomain if there is one.
Upvotes: 0
Views: 23
Reputation: 146510
You just need a simple server block to listen on example.com and redirect to example.io
http {
map $server_name $redirect_to {
default example.io;
"~*^(.*)\.example.com$" $1.example.io;
}
server {
listen 80;
listen 443 ssl;
server_name example.com *.example.com;
ssl_certificate ...;
ssl_certificate_key ....;
return 302 $scheme://$redirect_to$request_uri;
}
Upvotes: 1