2011-07-26 50 views

回答

0

您可以通過兩種方式做到這一點,與位置:

# the ?<u> assigns the capture to $u. Some older pcres need ?P<u> 
location ^/read/(?<u>[0-9]+)/?$ { 
    rewrite^/read/?u=$u last; 
} 

或只是一個改寫:

rewrite ^/read/([0-9]+)/?$ /read/?u=$1 last; 

nginx的將追加默認查詢字符串(你可以禁用的行爲通過在重寫目標的末尾添加另一個?)。

+0

我能夠通過 重寫^/read /([0-9] +)/?$/read /?u = $ 1來獲得所需的行爲。我的下一個問題是我應該使用國旗作爲最後的還是永久的。哪一個對SEO更好 –

+0

永久標誌會向客戶端發送301重定向,告訴它自己讀/讀/?u = $ 1。使用last將執行內部重定向,並且客戶端的地址欄仍將顯示/讀取/ 123。 – kolbyjack

+0

很酷謝謝..我感謝你的幫助 –

0

給下面的一個嘗試:

rewrite ^read/([0-9]+)/$ /read/?u=$1 permanent; 

IfIsEvil - 因此直接重寫選項。