nginx rewrite将二级域名url指向到主域名,并作为domain参数传递

1100 查看

将子域名
http://wap.baidu.com/qq55/id56.html

指向到
http://www.baidu.com/?domain=wap&page=qq&size=55&id=id56

nginx配置如下:

set $sub_domain “”;
if ( $host ~* (.*)\.baidu\.com ){
set $sub_domain $1;
}
if ( $sub_domain != “www” ){
rewrite ^/([a-zA-Z]+)(\d+)/(\w+).html$ /index.php?domain=$sub_domain&page=$1&size=$2&id=$3 last;
}