I have an unknown number of domains that match a pattern like www.abc123.example.com
. Where the number after "abc" is unknown. I thought perhaps I could use a rewrite rule with the regex ~*(www\.abc\w+)
Something like:
server_name ~*(www\.abc\w+)
rewrite ~*(www\.abc\w+)\.example\.com (abc\w+)\.example\.com;
Unfortunately, that does not seem to work, and the uri does not change. My other thoughts were perhaps attempting to set/rewrite the $uri value but I have been unsuccessful with that as well.
I am not sure if I am failing to match the uri value or failing to rewrite the uri (or both).
I was able to fine this:
if ($host ~* ^www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*) http://$host_without_www$1 permanent;
}
Unfortunately, that rewrites all 'www' traffic and not just www.abc123. Any help is appreciated. Thank you.