V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
kennedy32
V2EX  ›  NGINX

nginx rewrite 冲突解决

  •  
  •   kennedy32 · 2015-08-27 11:41:02 +08:00 · 2557 次点击
    这是一个创建于 3165 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想要实现的效果是

    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 那样解析出现错误

    2 条回复    2015-08-27 20:15:49 +08:00
    akira
        2
    akira  
       2015-08-27 20:15:49 +08:00
    拆开来写啊,干嘛非要写在一起
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5425 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:50 · PVG 15:50 · LAX 00:50 · JFK 03:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.