etrader
February 14, 2013, 11:05pm
1
I want to rewrite subdomains by adding a separate server for subdomains
as
server {
server_name domain.com
…
}
server {
server_name *.domain.com
}
but how I can I ass a rewrite rule int the second server to process
subdomain requests as
keyword.domain.com/query=some to
domain.com/script.php?query=some&sub=keyword
Posted at Nginx Forum:
etrader
February 14, 2013, 11:51pm
2
I’d take a look at using pattern matching in a map
( Module ngx_http_map_module ) and redirecting if the default
value isn’t found? Maybe not the most effective, but simpler to
maintain…
Steve
etrader
February 15, 2013, 6:48am
3
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.
etrader
February 15, 2013, 7:22am
4
On Feb 15, 2013, at 9:48 , Darren P. wrote:
set $keyword $1;
}
if ($request_uri ~* ^/query=(.+)) {
return 301 http://domain.com/script.php?query=$1&sub=$keyword ;
}
}
Oh, NO!
server {
server_name ~^(?.+).domain.com$;
return 301
http://domain.com/script.php?query=$arg_query&sub=$keyword ;
}
Or if the server may process something expect “query”:
server {
server_name ~^(?.+).domain.com$;
if ($arg_query) {
return 301
http://domain.com/script.php?query=$arg_query&sub=$keyword ;
}
…
}
–
Igor S.