2015-04-23 169 views
0

我想讓example.com/language/en指向example.com/language?lang=en我已經有了可以使用的@language(類型,有還是一些我最後解釋的bug),但不幸的是我不知道如何讓@language和@ extensionless-php同時工作,我通過刪除@ extensionless-php來測試@language代碼位置/並添加@location。 而現在,它接受像這樣//example.com/language/en/en/en這樣的多個參數,並且我希望它返回404錯誤(如果它有多於1個/在語言後面)漂亮的URL /乾淨的URL + nginx

當前配置:

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; 
} 

回答

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;