2015-08-28 70 views
1

我已經經歷了很多不同的問題看起來已經回答了有關如何重寫動態URL,並且不管是什麼原因,我不能讓他們用來爲我工作的代碼。我知道我需要編輯.htaccess文件。重寫動態網址,以友好的URL

當前網址:example.com/search/profileview.php?storeid=1 &店=水產成癮

理想網址:example.com/search/profileview/aqua-addicts.html

如果這是不可能的,我會很好的處理從URL中刪除?,&和=的任何內容。這是我目前正在嘗試在.htaccess中不起作用。

編輯:潔膚不工作 我有一個頁面,其基於搜索條件的結果。從該頁面的鏈接是: 這相當於 example.com/search/profileview.php?storeid=1 &店=水產成癮

我希望能夠點擊鏈接,並有網址更改爲友好版本。

RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} \s/+profileview\.php\?storeid=([^&]*)&.*?store=([^&\s]*) [NC] 
RewriteRule^profileview-storeid-%1-store-%2.html? [R=302,L] 

RewriteRule ^profileview-storeid-([^-]+)-store-([^.]+)\.html$ profileview.php?storeid=$1&store=$2 [L,QSA,NE] 

任何幫助表示讚賞。我知道這對一些人來說可能是一個簡單的改變,但我現在一直在試圖弄清楚這一點。

+0

而不是*重定向*古道新計劃,調整你的HTML和PHP腳本輸出新的URL通過本身。 - 「不工作」不是一個非常詳細的問題描述。 – mario

+0

規則看起來不錯,請解釋什麼是不工作? – starkeen

回答

1

試試這個。它不會自動應用重定向,但可以刪除不需要的?來自網址。

RewriteEngine On 
RewriteRule ^search/profileview/(.*).html?$ search/profileview.php?storeid=$1&store=$2 [QSA,NC,L] 

,然後可以調整你的永久鏈接像搜索/ profileview/AQUA-addicts.html

+0

利用這一點,我將需要手動創建靜態URL爲每一個動態網址? – EricB

+0

如果storeid和store的值是動態生成的,則不需要手動創建URL。在search/profileview /之後簡單地使用變量來傳遞商店的值。即動態url:search.profileview.php?storeid = <?php echo $ storeid;?>&store = <?php echo $ store;?>你需要在重寫後調整你的固定鏈接,例如:search/profileview/<? php echo $ store;?>。html – Rehmat

+0

謝謝你的幫助! – EricB

0

試試這個

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule ^search/profileview/([^/]+).html search/profileview.php?storeid=1&store=$1 [L] 
</IfModule> 
+0

謝謝您的答覆,但這並沒有進行什麼工作,我試圖做 – EricB