2013-08-04 27 views
0

這裏是我當前的URL:重寫規則 - htaccess的

?p=new-homes-by-east-homes&id=416&name=east-homes 

這裏是我想有:

?p=new-homes-by-east-homes&id=416 

到目前爲止,我已經生成使用的.htaccess這樣:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/ 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^p=new-homes-by-([^/]+)&id=([0-9]+)?$ ?p=new-homes-by-place&id=$2&name=$1 [L] 

然而,這實際上起作用,但我錯過了新網址?p=new...前面的問號。

當我把問號,它跳轉到主頁。

+0

那麼,是URL在哪裏? 'yourdomain.com/?p = new ...'可以詳細介紹一下。 – Prix

+1

對於漂亮的網址,您通常會忽略鍵值表示法和查詢字符串'?'標記。但是你爲什麼要重寫呢?如果您只需要刪除'&name =',那麼只需調整您的輸出代碼,不要將其包含在鏈接中。而且你可以在PHP中提取'east-homes'位。 – mario

回答

1

您無法匹配RewriteRule模式中的查詢字符串。你需要匹配對%{QUERY_STRING} VAR在RewriteCond然後使用反向引用:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/ 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{QUERY_STRING} ^p=new-homes-by-([^/]+)&id=([0-9]+)?$ 
RewriteRule ^/?$ /?p=new-homes-by-%1&id=%2&name=%1 [L]