使用.htaccess替换URL字符串

问题描述 投票:0回答:1

我正在尝试将URL中的字符串从?ref=替换为?tracking=

我的网址看起来像这样:

http://mywebsite.com/store/index.php?route=product/product&path=18_40&product_id=214232?ref=12345

并且我希望链接阅读:

https://vaulteksafe.com/store/index.php?route=product/product&path=18_20&product_id=214282?tracking=12345

请注意,URL每页都会更改。因此,我要更改的唯一内容是?ref

我熟悉.httaccess的基础知识,因此不确定我要完成的目标是否可行。我尝试了在堆栈溢出中找到的其他代码,例如RewriteCond %{QUERY_STRING},但没有一个起作用。

非常感谢您提供任何帮助,也可以反馈我是否可以尝试做。谢谢!

.htaccess
1个回答
0
投票

尝试以下,

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/store/index.php$
RewriteCond %{QUERY_STRING} ^route=(.*)&path=(.*)&product_id=(.*)?ref=(.*)$
RewriteRule ^ index.php?route=%1&path=%2&product_id=%3?tracking=%4
© www.soinside.com 2019 - 2024. All rights reserved.