如何使用 htaccess 添加条件 url 变量



>我使用以下代码:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)post_type=product(&|$)
RewriteCond %{QUERY_STRING} !(^|&)product_cat=xyz
RewriteRule ^(.*)$ http://www.example.com/?%{QUERY_STRING}&product_cat=xyz

但它不起作用。

我需要添加变量"product_cat=xyz",其中query_string包含"post_type=产品",它不仅包含"product_cat=xyz"。

例子:如果 url 是"http://www.example.com/?post_type=product&product_cat=xyz",那么 htacces 会保持不变。

如果 url 是"http://www.example.com/?post_type=product",那么 htacces 必须添加"&product_cat=xyz"

:-)你能帮帮我吗?提前谢谢。

您可以使用:

RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)post_type=product(&|$)
RewriteCond %{QUERY_STRING} !(^|&)product_cat=xyz(&|$)
RewriteRule ^ http://www.example.com/?product_cat=xyz [QSA,L]

最新更新