今天項目中有一個手機站點需要用*.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; }
心中有那么點小竊喜!記錄之!