301 redirect - nginx second-level domain name redirects to the directory
世界只因有你
世界只因有你 2017-05-16 17:17:35
0
2
692

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?

世界只因有你
世界只因有你

reply all(2)
Ty80
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

習慣沉默

Thank you very much Daniel, this method is better and solved

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template