how to rewrite or redirect a subdomain?

Igor Sysoev is at rambler-co.ru
Wed Aug 8 18:23:35 MSD 2007


On Wed, Aug 08, 2007 at 10:16:44PM +0800, Steve Chu wrote:

> I digged the nginx rewrite module, found that it is hard to
> rewrite/redirect a subdomain, here's my situation:
> I wanna rewrite/redirect "http://xxx.yyy.example.com" to
> "http://yyy.example.com/xxx".
> I found there's a Variables $host, but how to split it to get "xxx",
> then use rewrite module?
> any idea?

     server {
         server_name  yyy.example.com;
         ...
     }

     server {
         server_name  xxx.yyy.example.com  *.www.example.com;

         if ($http_host ~ "^(.+?)\.") {
             set  $host  $1;
         }

         rewrite  ^   http://yyy.example.com/$host;
     }


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list