regex - WordPress 重定向插件在目标 URL 中包含查询参数

标签 regex wordpress .htaccess redirect

我正在使用 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/了解更多详情。

参见下面的示例:

enter image description here

但是,在那个例子中,我使用了这个 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/

相关文章:

c# - 提取文件名部分以解决文件名冲突

node.js - 如何使用 Express 添加 MIME 类型

linux - .htaccess - 将子目录添加到所有目录

.htaccess - HTTP 到 HTTPS .htaccess

html - <a> 在 header : only part of it works? 中

php - 如何停止从生产服务器访问管理面板

r - 如何提取多个下划线之间的数字

Javascript 正则表达式 : How to put a variable inside a regular expression?

javascript - 如何在javascript中更改小写文本但保留大写字母?

wordpress - 如何从 WooCommerce 购物车中删除 Shipping?