Regular expressions in server_name: pattern length

Tobia Conforto tobia.conforto at gmail.com
Mon Feb 8 23:03:33 MSK 2010


Michael Shadle wrote:
> server_name ~^(.+)\.domain\.com$;
> rewrite ^ http://foo.com/index.php?title=$1 permanent;

Either do as Maxim suggested, with the P:

server_name ~ ^(?P<domain>.+)\.domain\.com$;
rewrite ^ http://foo.net/script/index.php?title=$domain permanent;

or save the capture into a variable:

server_name ~^(.+)\.domain\.com$;
set $domain $1;
rewrite ^ http://foo.net/script/index.php?title=$domain permanent;


Tobia



More information about the nginx mailing list