I have urls like this:
And I want nginx to replace dots "." characters in the subdomain part of the hostname by dashes "-", so this would result in :
I already have a server block that catches the urls with dots in the "prefix" variable, but I could not find any documentation on how to rewrite url so that is replaces characters in "prefix" without using lua/…:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name "~^(?<prefix>[w.]+).somedomain.com$";
rewrite 302 "$scheme://What do i put in here?.somedomain.com$request_uri";
}
A big thanks for people that will try to help on this!
2
Answers
You could capture both sides of the
.
with separate captures, for example:Use a map to capture the subdomains: