2012-04-23 116 views
0

我已經實現的URL畝PHP Web站點重寫URL重寫動態頁面

這裏我需要顯示我的鏈接作爲

mydomain.com/komet-india/Best-Indian-Hill-Stations-1/Delhis-Hotel 

這裏Best-Indian-Hill-Stations,1,Delhis-Hotel是動態值 我再舉一個例子太

mydomain.com/komet-india/Popular Indian Pilgrimages-2/new-Hotel 

這裏

Popular Indian Pilgrimages,2,new-Hotel 

是動態值。

第一個參數是類,第二個是id,第三個是

我寫了以下網址做到這一點看我的代碼

Rewrite Rule (\d+)-(\d+)/(.*)/? hotel-detail.php?title=$1&id=$2&top=$3&hotel=4 [nc] 

的酒店的名字,但它的結果未找到頁面

有沒有人給我一個解決方案?

+1

'Rewrite Rule' - >'RewriteRule' – 2012-04-23 06:56:19

+0

我只是使用'RewriteRule(。*)hotel-detail.php?$ 1'將每一頁(除了靜態資源,如CSS,圖像)發送到PHP,然後解析PHP中的查詢字符串。 – 2012-04-23 06:56:44

回答

0

我有幾乎相同的問題。我得到了最好的方法來完成這件事。 .htaccess文件

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

URL解析代碼

$url = isset($_GET['url']) ? $_GET['url'] : null; 
    $url = str_replace(".html", "", $url); 
    $url = str_replace("-", "_", $url); 
     //you could use rtrim(); but I had some trouble when the url had the "t" as the ending character. 
    //$url = rtrim($url, '.html'); 
    $url = explode('/', $url); 

這樣你會得到$網址陣列的URL。

這樣說mydomain.com/komet-india/Best-Indian-Hill-Stations-1/Delhis-Hotel

$url[0] = komet_india 
$url[1] = Best_Indian_Hill_Stations_1 
$url[2] = Delhis_Hotel 
1

嘗試重寫規則...

RewriteRule komet-india/(.*)-(\d+)/(.*)$ hotel-detail.php?title=$1&id=$2&top=$3&hotel=4 [NC,L] 
0

嘗試改變你的重寫規則如下。塔應該CREA

Rewrite Rule (.*)-(\d+)/(.*)/? hotel-detail.php?title=$1&id=$2&top=$3&hotel=4 [nc] 

還林不知道,如果你需要的KOMET印在那裏。但我不知道你的本地主機設置。