Php 用htaccess搜索替换查询字符串

Php 用htaccess搜索替换查询字符串,php,regex,.htaccess,Php,Regex,.htaccess,我的网站url是这样的 https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&twdg_wsac=1 我想用htaccess替换这个url的某些部分,所以最终的输出应该是这样的 https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&custom_posts=

我的网站url是这样的

https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&twdg_wsac=1
我想用htaccess替换这个url的某些部分,所以最终的输出应该是这样的

https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&custom_posts=1
RewriteEngine on
RewriteRule ^&twdg_wsac$ &custom_posts
所以我在htaccess文件中做了如下更改

https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&custom_posts=1
RewriteEngine on
RewriteRule ^&twdg_wsac$ &custom_posts
但它不起作用。正如您在url中看到的,还有
twdg_wsac=1
。所以最后一个“1”是post的分页,因此它将根据post计数动态更改

有人能告诉我怎么做吗? 任何帮助和建议都会非常有用。谢谢

更新
url中的所有参数都是动态生成的,我的意思是这些是过滤器参数。所以它们不能相同,除了
twdg_wsac

尝试下面的方法,我们正在对查询字符串进行重写

RewriteEngine On
RewriteCond %{QUERY_STRING} ^orderby=(.+)&s=(.+)&post_type=(.+)&twdg_wsac=([\d]+)$
RewriteRule ^ %{REQUEST_URI}?orderby=%1&s=%2&post_type=%3&custom_posts=%4
重新启动发动机 RewriteCond%{QUERY_STRING}twdg_wsac=([\d]+)$
重写规则^%{REQUEST\u URI}?orderby=low\u to\u high&s=demo+post&post\u type=post&custom\u posts=%1[L]

谢谢您的回答,但是
orderby=low\u to\u high&s=demo+post&post\u type=post&
将是动态的,我的意思是它们是过滤器参数,所以每次都不相同。@NewUser尝试更新,我还没有试过,如果有什么问题,请告诉我。我不确定是否能理解。twdg_wsac=1表示“当前是第一页”?如果是,您的url:/page/1/?ord如何。。。/1/并不意味着它是第一页?你有两次信息吗?