I am setting up a 301 redirect server for the websites I host. When I get a new customer, I don't want to go edit the domain list in the server block below. Instead of a hard-coded domain in the nginx configuration, I want to redirect anydomain-here.com to 301 -> www.anydomain-here.com
All domains that are bare (ie domain.com) will be redirected to www.domain.com
server {
server_name domain-requested.com;
rewrite ^/(.*)$ http://www.domain-requested.com/$1 permanent;
}
In the example above, is it possible to change domain-requested to a variable? This would allow the server to redirect any site that doesn't have a subdomain, such as www.