is the second-level domain name redirected to the directory. Because the second-level domain name is abandoned, it needs to be re-301.
For example, jianfei.xxx.com redirects to www.xxx.com/jianfei
In addition, www needs to be excluded. How to write it?
PHP中文网2017-05-16 17:19:35
if ($host = 'jianfei.xxx.com' ) {
rewrite ^/(.*)$ http://www.xxx.com/jianfei/ permanent;
}
------------------Change it--------
The questioner said that jianfei is a variable, so the above method will not work.
Consider whether you can create two configuration files
www.xxx.com.conf, no need to rewrite
server {
listen 80;
server_name www.xxx.cn xxx.cn;
other.xxx.com.conf, specially used to rewrite to www domain name
server {
listen 80;
server_name ~^(.*).xxx.com$;
set $sub_name ;
#if ($sub_name ~* (jianfei|gongjingmilan|others) ){#如果是部分子域名要跳转可以枚举或正则匹配,全部子域名都跳可以注释掉
rewrite ^/(.*)$ http://www.xxx.com/$sub_name/;
#}
The test works