Regex for rewrite of subdomains

Darren Pilgrim list_nginx at bluerosetech.com
Fri Feb 15 05:48:11 UTC 2013


On 2013-02-14 14:05, etrader wrote:
> I want to rewrite subdomains by adding a separate server for subdomains as
[...]
 > keyword.domain.com/query=some to
 > domain.com/script.php?query=some&sub=keyword

server {
   server_name *.domain.com;

   if ($http_host ~* (.+)\.domain.com$) {
     set $keyword $1;
   }

   if ($request_uri ~* ^/query=(.+)) {
     return 301 http://domain.com/script.php?query=$1&sub=$keyword;
   }
}

I'm not sure a map would be faster in this case because you don't need a 
multitude of patterns.



More information about the nginx mailing list