我有这个网址:
http://example.org/wiki/index.php?title=Special:UserLogin
&returnto=Special%3AWatchlist&returntoquery=&warning=watchlistanontext
我希望将请求重定向到:
https://example.org/login/wiki/?returnTo=Special%3AWatchlist
该部分title=Special:UserLogin
是应触发的部分RewriteRule
。其他参数可以更改(尤其是的值returnto=xxx
);应该将其保留为目标URL。该参数returnto=xxx
应映射到returnTo=xxx
目标URL中(大写的“ T”)。
阅读文档后,我已经尝试过RewriteRule
:
RewriteCond %{QUERY_STRING} title=Special:UserLogin&?(.*)
RewriteRule index.php https://example.org/login/wiki/?%1 [R=301,L]
据我所知,这基本上也行得通,除了一件事:returnto参数仍然写入returnto
而不是returnTo
。如何更改参数名称的大小写以解决此问题?
您需要修复正则表达式以捕获正确的查询参数。您可以使用以下规则:
RewriteCond %{QUERY_STRING} (?:^|&)title=Special:UserLogin(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)returnto=([^&]+) [NC]
RewriteRule ^index\.php$ https://example.org/login/wiki/?returnTo=%1 [R=301,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句