我正在使用 WordPress 重定向插件将旧登录页面重定向到新域。
我能够匹配包含任何查询字符串的 URL,这会 100% 重定向到新域。
例子: 来自:
/page/(\?.+)?$
收件人:
https://new-site.com/page
如何在插件的目标 URL 中包含查询字符串,以便浏览器重定向到如下内容:
https://new-site.com/page?q=test&s=test2
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /usbed/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /usbed/index.php [L]
</IfModule>
# END WordPress
最佳答案
其实很简单
只需将目标 URL 设置为:
https://new-site.com/page$1
$1
指的是你提供的RegEx中抓取的(\?.+)
的内容。
参见 https://redirection.me/support/redirect-regular-expressions/了解更多详情。
参见下面的示例:
但是,在那个例子中,我使用了这个 RegEx:/page(|/|/?\?.+)$
,它匹配这些 URL:(你可以在 RegExr 上测试它) ,但您需要使用 \
转义 /
;因此您将使用 \/page(|\/|\/?\?.+) $
,Redirection 插件也接受它)
http://example.com/page
http://example.com/page/
http://example.com/page?q=test&s=test2
http://example.com/page/?q=test&s=test2
关于regex - WordPress 重定向插件在目标 URL 中包含查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49232837/