Regex 如何使用mod_rewrite交换URL参数并丢弃其他参数?

Regex 如何使用mod_rewrite交换URL参数并丢弃其他参数?,regex,apache,url,mod-rewrite,configuration,Regex,Apache,Url,Mod Rewrite,Configuration,我需要重定向简化的: /search.html?param1=val1&param2=val2&param3=val3&location=UK 致: 参数可以是任意顺序或缺失,位置是地图文件中带有扩展名的代码(英国等) 如果没有匹配的参数,请重定向到: /search-info/ 位置扩展的当前代码: RewriteMap location_map txt:/path/to/locations_map.txt RewriteCond %{REQUEST_URI} .*

我需要重定向简化的:

/search.html?param1=val1&param2=val2&param3=val3&location=UK
致:

参数可以是任意顺序或缺失,位置是地图文件中带有扩展名的代码(英国等)

如果没有匹配的参数,请重定向到:

/search-info/
位置扩展的当前代码:

RewriteMap location_map txt:/path/to/locations_map.txt
RewriteCond %{REQUEST_URI} .*search.html.* [NC]
RewriteCond %{QUERY_STRING} .*location=([^&]+).* [NC]
RewriteCond ${location_map:%1} ^(.*)$
RewriteRule ^(.*)$ /search/%1/ [R=301]

如何交换参数名称并丢弃不需要的参数(即上面的param3)?

如果不是不断变化的参数顺序要求,这将起作用。你不能把订单定下来吗

RewriteMap location_map txt:/path/to/locations_map.txt
RewriteCond %{REQUEST_URI} /search.html [NC]
RewriteCond %{QUERY_STRING} (param1=(.+?)&)?(param2=(.+?)&)?(param3=(.+?)&)?location=(.+?) [NC]
RewriteRule ^(.*)$ /search/${location_map:%7}/?arg4=%4&arg5=%2 [R=301,last]

RewriteCond %{REQUEST_URI} /search.html [NC]
RewriteRule / /search-info/ [last]
RewriteMap location_map txt:/path/to/locations_map.txt
RewriteCond %{REQUEST_URI} /search.html [NC]
RewriteCond %{QUERY_STRING} (param1=(.+?)&)?(param2=(.+?)&)?(param3=(.+?)&)?location=(.+?) [NC]
RewriteRule ^(.*)$ /search/${location_map:%7}/?arg4=%4&arg5=%2 [R=301,last]

RewriteCond %{REQUEST_URI} /search.html [NC]
RewriteRule / /search-info/ [last]