Rewrite Subdomains to Paths

Valentin V. Bartenev ne at vbart.ru
Wed Mar 21 20:33:02 UTC 2012


On Thursday 22 March 2012 00:15:00 Kurtis Mullins wrote:
> Hey,
> 
> Is it possible to rewrite subdomains to paths? I want to do something like
> this:
> 
> x.example.com/foo/bar/ -> www.example.com/x/foo/bar/
> 

    server {
        server_name ~^(?P<subdomain>.+)\.example\.com$;

        location / {
            return 301 http://www.example.com/$subdomain$request_uri;
        }
    }

 wbr, Valentin V. Bartenev



More information about the nginx mailing list