nginx rewrite 冲突解决

2015-08-27 11:41:02 +08:00
 kennedy32

想要实现的效果是

abc.com/hello => abc.com/article.php?link=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;        
}

目前的问题是 abc.com/hello 是没问题的, abc.com/en/hello 也是没问题的, abc.com/en/会被当成 hello 那样解析出现错误

2614 次点击
所在节点    NGINX
2 条回复
arnofeng
2015-08-27 13:20:35 +08:00
akira
2015-08-27 20:15:49 +08:00
拆开来写啊,干嘛非要写在一起

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/216349

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX