[英].htaccess redirect based on query string and remove query string
我需要具有重定向指令,以將帶有查詢字符串的舊URL重定向到沒有查詢字符串的新URL。 並且新的URL取決於查詢字符串的值。 例如:
我想要:http:// www.mydomain.com/product.php?id_product=AAA
將重定向到:
http:// www.mydomain.com/product-name-for-product-number-1
和
http:// www.mydomain.com/product.php?id_product=BBB
將重定向到:
http:// www.mydomain.com/this-is-different-product-name-for-product-number-2
提前致謝。
您可以執行以下類型的重定向:
來自:http:// www.mydomain.com/product-name-for-product-number-AAA
到:http:// www.mydomain.com/product.php?id_product=AAA&name_product=產品名稱
來自:http:// www.mydomain.com/this-is-different-product-name-for-product-number-2
到:http:// www.mydomain.com/product.php?id_product=BBB&name_product=this-is-different-product-name
您無法從htaccess文件中動態檢索產品名稱,執行此操作的唯一方法是:
RewriteRule ^(.+)-for-product-number-(.+)$ ^product.php?id_product=$2&name_product=$1
或者您需要為每個產品創建一個重寫器(您可以通過從數據庫檢索所有產品ID和名稱的腳本生成.htaccess):
RewriteRule ^product-name-for-product-number-1$ product.php?id_product=AAA
RewriteRule ^this-is-different-product-name-for-product-number-2$ product.php?id_product=BBB
在我看來,您無法基於查詢字符串執行重定向。 因此,您將必須添加[QSA]
標志並重定向到腳本,該腳本將能夠通過查詢字符串進行重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.