漂亮的URL / Clean URL + nginx

时间:2015-04-23 17:56:05

标签: nginx clean-urls pretty-urls

我正试图让example.com/language/en指向example.com/language?lang=en我已经让@language工作了(有点,还有一些我在结束)但不幸的是我不知道如何让@language和@ extensionless-php同时工作,我通过删除位置中的@ extensionless-php并添加@来测试@language代码地点。 它现在的方式是接受多个这样的参数,例如//example.com/language/en/en/en,如果语言

当前配置:

location / {
    try_files $uri $uri.html $uri/ @extensionless-php;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

location @language {
    rewrite ^/language/(.*)$ /language.php?lang=$1 last;
}

1 个答案:

答案 0 :(得分:0)

答案就是从@language中删除rewrite ^/language/(.*)$ /language.php?lang=$1 last;,编辑正则表达式,这样当URI为/language/en/时就会出现404错误

location / {
    try_files $uri $uri.html $uri/ @extensionless-php;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

rewrite ^/language/([^/]+)$ /language.php?lang=$1 last;