Quantcast
Channel: Nginx Forum
Viewing all articles
Browse latest Browse all 53287

Re: Regex for rewrite of subdomains

$
0
0
On Feb 15, 2013, at 9:48 , Darren Pilgrim wrote:

> 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;
> }
> }

Oh, NO!

server {
server_name ~^(?<KEYWORD>.+)\.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 ~^(?<KEYWORD>.+)\.domain\.com$;

if ($arg_query) {
return 301 http://domain.com/script.php?query=$arg_query&sub=$keyword;
}
...
}


--
Igor Sysoev
http://nginx.com/support.html

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Viewing all articles
Browse latest Browse all 53287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>