如何使用.htaccess重定向字符串?

时间:2015-08-14 18:21:45

标签: .htaccess redirect

我需要为几千个不断更改的URL设置重定向。

从此 - example.com/product?product_id=blue_alwayschanging

至此 - example.com/widget?product_id=blue_alwayschanging

由于我的知识有限,我认为下面的内容是朝着正确方向迈出的一步。我错过了什么?它没有用。

RewriteEngine on
RedirectMatch 301 ^/product?product_id=blue_.* /widget?product_id=.*

1 个答案:

答案 0 :(得分:1)

RewriteEngine激活mod_rewrite。而RedirectMatch是mod_alias指令。 RedirectMatch也与查询字符串不匹配,但您不需要,因为查询字符串只需要不变地传递给目标。

尝试使用以下单行替换当前代码:

RedirectMatch 301 ^/product /widget