.htaccess 重定向多个查询字符串

.htaccess 重定向多个查询字符串,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我需要用查询字符串重定向一些URL。url文件名和查询字符串参数名会更改,但查询字符串值始终相同。我已经创建了一个测试htaccess文件,该文件适用于单个url,但我希望有一个更优雅的方法来更改它,因为我有许多url需要更改 htaccess测试文件 RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} (^|&)*=0(&|$) [NC] RewriteRule ^page1\.html$ page1.html?

我需要用查询字符串重定向一些URL。url文件名和查询字符串参数名会更改,但查询字符串值始终相同。我已经创建了一个测试htaccess文件,该文件适用于单个url,但我希望有一个更优雅的方法来更改它,因为我有许多url需要更改

htaccess测试文件

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)*=0(&|$) [NC]
RewriteRule ^page1\.html$ page1.html?query1=1 [R=301, L, NC]
我有这样一个url:

http://www.example.com/page1.html?query1=0
http://www.example.com/page2.html?query2=0
http://www.example.com/page3.html?query3=0
我需要把它改成这样:

http://www.example.com/page1.html?query1=1
http://www.example.com/page2.html?query2=1
http://www.example.com/page3.html?query3=1
任何帮助都将不胜感激。

您可以在此处使用正则表达式或运算符

如果query1、query2等只是示例,实际上是不同的字符串,那么使用

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (?:^|&)(query1|query2|query3)=0(&|$) [NC]
RewriteRule ^((page1|page2|page3)\.html)$ $1?%1=1 [R=301,NC,L]
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (?:^|&)(query[123])=0(&|$) [NC]
RewriteRule ^(page[123]\.html)$ $1?%1=1 [R=301,NC,L]
如果参数确实具有后跟序号的公共前缀查询,则使用

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (?:^|&)(query1|query2|query3)=0(&|$) [NC]
RewriteRule ^((page1|page2|page3)\.html)$ $1?%1=1 [R=301,NC,L]
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (?:^|&)(query[123])=0(&|$) [NC]
RewriteRule ^(page[123]\.html)$ $1?%1=1 [R=301,NC,L]