2016-11-18 71 views
2

Url https://example.com/profile/chico 必須被nginx理解爲: https://example.com/profile/?username=chico(當前工作的url)。翻譯的url路徑查詢nginx的參數

https://example.com/profile/當前工作爲好,因爲它解決了目前到index.php,沒有用戶名PARAM。

我現在有

location /profile/ { 
    index /profile/index.php; 
} 

有在網絡上關於這個很多不同的東西,我沒有具體是什麼,我需要找到。

也試過

location /profile/ { 
    rewrite ^/profile/(.*)$ /profile/?username=$1; 
} 

回答

2

嘗試:

location /profile/ { 
    try_files $uri @rewrite; 
} 
location @rewrite { 
    rewrite ^/profile/(.+)$ /profile/index.php?username=$1 last; 
    rewrite^/profile/index.php last; 
} 

如果第一rewrite比賽,第二rewrite被忽略。在使用.php擴展名重寫URI後,處理將移至不同的location塊。

查看this document瞭解更多。

編輯:添加try_files塊來處理靜態內容。

+0

謝謝你,走近了404(例如/profile/assets/js/main.js工作,頁面使用用戶名VAR實際負載,但在資產上的頁面結果不能被發現,同樣的圖像和css文件) –

+0

好的,沒有意識到你在那個位置有靜態內容。答案已更新。 –

+0

太棒了。謝謝。 –