search

Home  >  Q&A  >  body text

url-rewrite - nginx rewrite conflict resolution

The desired effect is
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
The current writing method is
location / {

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

The current problem is that abc.com/hello is no problem, abc.com/en/hello is also no problem, abc.com/en/ will be parsed as hello and errors will occur

曾经蜡笔没有小新曾经蜡笔没有小新2871 days ago573

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 17:24:08

    /en/ is also used as a rewrite rule

    reply
    0
  • Cancelreply