2014-01-21 112 views
0

我想重寫下面的3個URL來翻譯成正確的頁面。PHP mod_rewrite&.htaccess乾淨的URL

highscore.php是我的主目錄

www.domain.com/clan/ 
    www.domain.com/highscore.php 

    www.domain.com/clan/Halos 
    www.domain.com/highscore.php?clan=Halos 

    www.domain.com/clan/Halos/Cooking 
    www.domain.com/highscore.php?clan=Halos&view=Cooking 

我已經在我的.htaccess如下:

RewriteEngine On 
    #RewriteBase/
    RewriteRule ^clan/([^/]*)$ /highscore.php?clan=$1&view=$2 [L] 

這成功的把下面網址:

www.domain.com/clan/Halos 

www.domain.com/highscore.php?clan=Halos 

以下URL轉到highscore.php頁面用空 '家族' 參數

www.domain.com/clan/ 

是映射

www.domain.com/highscore.php?clan= 

我m試圖讓它映射到

www.domain.com/highscore.php 

當我去

www.domain.com/clan/Halos/Cooking 

它只能識別第一個參數「暈」,而不是第二個「烹飪」?它需要我:

www.domain.com/highscore.php?clan=Halos 

非常困惑,我需要一些方向,我正在做什麼正確和/或錯誤。

回答

1
RewriteEngine On 
#RewriteBase/

#Rewrite base path 
RewriteRule ^clan/$ /highscore.php [L] 
#Rewrite clan path 
RewriteRule ^clan/([^/]*)$ /highscore.php?clan=$1 [L] 
#Rewrite view path 
RewriteRule ^clan/([^/]*)/([^/]*)$ /highscore.php?clan=$1&view=$2 [L] 
0

您的重寫規則在表達式中沒有第二個提取部分,因此只提取一個參數。這裏是如何提取第二個參數:

RewriteRule ^clan/([^/]*)/([^/]*)$ /highscore.php?clan=$1&view=$2 [L] 

現在你在這裏提取兩個部分(用括號表示)。