簡體   English   中英

將動態URL重寫為友好URL

[英]Rewrite Dynamic URLs to Friendly URLs

我研究了許多有關如何重寫動態URL的不同問題,無論出於何種原因,我都無法獲得它們用於我的代碼。 我知道我需要編輯.htaccess文件。

當前網址:example.com/search/profileview.php?storeid = 1&store = aqua-addicts

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

如果不可能,那么可以從URL中刪除?,&和=的所有內容。 這是我目前在無法正常工作的.htaccess中嘗試的操作。

編輯:澄清無法正常工作,我有一頁根據搜索條件生成結果。 該頁面上的鏈接是:等同於example.com/search/profileview.php?storeid=1&store=aqua-addicts

我希望能夠單擊鏈接並將URL更改為友好版本。

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]

任何幫助表示贊賞。 我知道對於某些人來說,這可能是一個簡單的更改,但是我已經嘗試解決了大約一天半的時間。

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

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

然后,您可以調整永久鏈接,例如search / profileview / aqua-addicts.html

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM