NGINX将PHP带参数的URL地址重定向二级或多级域名访问

今天项目中有一个手机站点需要用*.m.domain.com的三级域名访问。

如手机站点的访问网址为m.domain.com,手机下面的会员实际访问地址为index.php?username=$username,需要定向为username.m.domain.com域名访问,直接看详情

location / {

if ($host ~* ^(.*).m.domain.com) {

set $username $1;

rewrite ^/ /index.php?username=$username ;

}

}

例二:

将子域名
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;
}

心中有那么点小窃喜!记录之!

原文地址:https://www.cnblogs.com/sandea/p/5714960.html