重写规则更改正则表达式以识别 URL 中的不同模式

Rewrite rule change regex to identify different pattern in the URL

以下重写配置仅重定向 url 形式

/fetchHomePage.action?site=eu

RewriteCond %{QUERY_STRING} ^site=(eu|jp|in)$ [NC]
RewriteRule ^/?fetchHomePage.action$ https://example.com/%1? [R=301,L,NC]

我应该在上面的正则表达式中更改什么,以便它甚至可以像

一样重定向 url

/fetchHomePage.action;jsessionid=60E508BF73717B6BE0C38D80769A0A22?site=eu

感谢这里的潜在客户?

匹配一个没有问题;在 url-路径中。

url-path with ";" is not matched as a query string you match it with the RewriteRule as you do with anything else.

因此,要匹配 jsessionid,您只需将其附加到匹配的 url-路径中,如下所示:

RewriteCond %{QUERY_STRING} ^site=(eu|jp|in)$ [NC]
RewriteRule ^/?fetchHomePage.action;jsessionid=60E508BF73717B6BE0C38D80769A0A22 https://example.com/%1? [R=301,L,NC]

不需要转义。至于jsession id的字符串本身,你可以随便匹配,比如(.*)?,可能还有更合适更具体的匹配方式,看你的喜好了。