2013-10-05 348 views
1

我有例如,這網址:Nginx的 - URL重寫規則

www.example.com/folder1/folder2/edit.php?username=nickname

其實我有這樣的重寫規則:

location/{ 
    root /var/www; 
    index index.php index.html index.htm; 

    # First rewrite rule output: www.example.com/nickname 

    rewrite ^/([A-Za-z0-9_]+)$ /folder1/folder2/user.php?username=$1; 

    # Second rewrite rule output: www.example.com/nickname/edit 

    rewrite ^/([A-Za-z]+)/edit$ /folder1/folder2/edit.php?username=$1; 
} 

但是,工作正常。

但我需要重寫我的網址是這樣的:

www.example.com/nickname/edit/info

它有幾個參數:

www.example.com/folder1/folder2/edit.php?username=nickname & info =基本

我什麼都試過,但沒有成功:

location/{ 
    root /var/www; 
    index index.php index.html index.htm; 

    # First rewrite rule output: www.example.com/nickname 
    rewrite ^/([A-Za-z0-9_]+)$ /folder1/folder2/user.php?username=$1; 

    # Second rewrite rule output: www.example.com/nickname/edit 
    rewrite ^/([A-Za-z]+)/edit$ /folder1/folder2/edit.php?username=$1; 

    # Here where I'm stuck 
    # www.example.com/nickname/edit/info 

    rewrite ^/edit/([A-Za-z]+)/info$ /folder1/folder2/edit.php?user=$1&info=$2; 
} 

回答

1

你的最後一次嘗試似乎已經混淆的edit位置。此外,沒有被傳遞給info因爲只有一個捕獲組,也許

rewrite ^/([A-Za-z]+)/edit/([A-Za-z]+)$ /folder1/folder2/edit.php?username=$1&info=$2;

反而會工作嗎?