Regular Expression global redirect

altiamge nginx-forum at
Sun Feb 26 07:27:12 UTC 2012

I'm not able to get either one of these to work. I just upgraded to
nginx 1.0.12 just to make sure my version wasn't an issue. I also
checked my PCRE version.

# pcretest
PCRE version 6.6 06-Feb-2006

Here are the errors I'm getting with each example:

Example 1
server {
     listen 80;
     server_name ~^www\.(?<domain>.+)$;
     rewrite ^ $scheme://$domain$request_uri? permanent;

## Error:
[emerg] pcre_compile() failed: unrecognized character after (?< in
"^www\.(?<domain>.+)$" at "domain>.+)$"

Example 2
server {
     server_name ^~www\.(?<domain>.*)$;
     return 301 http://$domain;

server {
     server_name ^~(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;
     location / {
          proxy_pass  http://websites;

## Error:
nginx: [emerg] unknown "domain" variable


Posted at Nginx Forum:,222984,222990#msg-222990

More information about the nginx mailing list