tags:

views:

95

answers:

2

Hi everyone,

I'm very new with Nginx, and now I want to use Nginx to generate new url from the url user passed.
Example:
User type to browser like http://us.domain.com, and I want Nginx generates to http://www.domain.com/?portal=us or http://domain.com/?portal=us.

How can I rewrite the nginx to do this?

Best regards,
Leakhina

A: 

You mean redirect, right?

http {
  # ...
  server {
    server_name us.domain.com;
    location / {
      rewrite ^/ http://www.domain.com/?portal=us;
    }
  }
}
rzab
A: 

Something not as fast, but more general:

server {
    listen       80;
    server_name  domain.com;
    if ($host ~* (.*)\.domain\.com ) {
       set $subdomain $1;
       rewrite (.*) http://domain.com/?portal=$subdomain;
    }
Martin Redmond