从斜杠词后重定向到查询

Redirection from after slash word to query

我在 .htaccess 的编码和重定向方面非常陌生。 我需要对很多带有 slug /brand/ 的 URL 进行重定向。 例如:

https://example.com/brand/AAA to /shop/?filter_marke=AAA
https://example.com/brand/BBB to /shop/?filter_marke=BBB
https://example.com/brand/CCC to /shop/?filter_marke=CCC

等等。

您可以使用 mod_rewrite 执行如下“重定向”:

RewriteEngine On

RewriteRule ^brand/(\w+)$ /shop/?filter_marke= [R=302,L]

规则的顺序可能很重要。这需要在任何现有重写之前接近 .htaccess 文件的顶部。如果这是一个 WordPress 站点,则需要在 之前 # BEGIN WordPress 评论标记。

替换字符串(第二个参数)中的</code>反向引用包含[=14之后的<em>字</em>的值=] 在 URL-path.</p> <hr /> <p><strong>更新:</strong></p> <blockquote> <p>I only forgot to mention that there is a slash after the variable, means the incoming link looks like <code>..../AAA/

在这种情况下,您可以简单地在模式末尾附加一个尾部斜杠,即。 ^brand/(\w+)/$。或者将尾部斜杠设为可选,以便两者都匹配。 IE。 ^brand/(\w+)/?$.