使用.htaccess扩展url参数

时间:2016-08-23 14:37:56

标签: .htaccess url parameters url-rewriting

有许多类似的.htaccess问题,但即使经过漫长的搜索,我也无法找到问题的答案。

我认为它应该相当简单,它超出了我的能力。

我需要重定向添加参数以将搜索参数扩展到另一个 - 具体来说我需要这个:

www.domain.com/?s=whatever

成为

www.domain.com/?s=whatever&post_type=product

每次,但显然只有 s 参数存在且 post_type 参数不存在。

在这种情况下,以正确的方式(在输入时管理参数)这样做是不可能的,这就是为什么我想用.htaccess绕过它。

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:1)

您可以在站点根目录中使用此规则.htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^s=[^&]+ [NC]
RewriteRule ^ %{REQUEST_URI}?post_type=product [QSA,L,R=302,NE]
相关问题