技术解析

nginx rewrite 冲突解决
0
2021-05-25 12:07:22
idczone

想要实现的效果是

abc.com/hello => abc.com/article.php?lin抗投诉服务器k=hello
abc.com/en/ => abc.com/index.php?lang=en
abc.com/en/hello => abc.com/article.php?link=hello&lang=en

目前的写法是

location / {
    try_files $uri $uri/ =404;
    if (!-e $request_filename ){
        rewrite ^/(.*)$ /article.php?link=$1 last;
    }
}
location /en/ {
    rewrite index index.php?lang=en;
    rewrite ^/en/(.*)$ /article.php?link=$1&lang=en last;        
}

用=或者~来进行优先级调整
参考 http://itpub.02252.com/?l=3&ref=www_iphone&order=1&dict=22&tj=www_normal_1_0_10_title&cltj=cloud_title&src=http%3A%2F%2Fblog.itpub.net%2F27181165%2Fviewspace-777202%2F#m/http://blog.itpub.net/27181165/viewspace-777202/

拆开来写啊,干嘛非要写在一起

数据地带为您的网站提供全球顶级IDC资源