简体   繁体   English

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

[英]WordPress Redirection plugin to include query parameters in target URL

I'm using the WordPress Redirection plugin to redirect old landing pages to a new domain.我正在使用 WordPress 重定向插件将旧登录页面重定向到新域。

I'm able to match URLs including any query strings and this redirects 100% to the new domain.我能够匹配包含任何查询字符串的 URL,这会将 100% 重定向到新域。

Example: From:示例:来自:

/page/(\?.+)?$

To:到:

https://new-site.com/page

How can I include query strings in the target URL of the plugin so that the browsers will redirect to something like this:如何在插件的目标 URL 中包含查询字符串,以便浏览器重定向到如下内容:

https://new-site.com/page?q=test&s=test2

.htaccess .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

It's quite simple, actually.其实很简单。

Just set the Target URL to:只需将目标 URL设置为:

https://new-site.com/page$1

$1 refers to the contents of the captured (\\?.+) in the RegEx you provided. $1是指您提供的 RegEx 中捕获的(\\?.+)的内容。

See https://redirection.me/support/redirect-regular-expressions/ for more details.有关更多详细信息,请参阅https://redirection.me/support/redirect-regular-expressions/

See sample below:请参阅下面的示例:

在此处输入图片说明

However, in that example, I used this RegEx: /page(|/|/?\\?.+)$ , which matches these URLs: (you can test it on RegExr , but you need to escape the / with a \\ ; hence you'd use \\/page(|\\/|\\/?\\?.+)$ , which is also accepted by the Redirection plugin)然而,在那个例子中,我使用了这个 RegEx: /page(|/|/?\\?.+)$ ,它匹配这些 URL: (你可以在RegExr上测试它,但你需要用\\转义/ ;因此你会使用\\/page(|\\/|\\/?\\?.+)$ ,这也被重定向插件接受)

http://example.com/page
http://example.com/page/
http://example.com/page?q=test&s=test2
http://example.com/page/?q=test&s=test2

How would you go about doing this same thing with the following using an index.html file?您将如何使用 index.html 文件对以下内容做同样的事情?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /appointments
RewriteRule ^appointments/index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /appointments/index.html [L]
</IfModule>

We have an application that lives in a subfolder /appointments that is primarily javascript and we need to redirect all additional url params (ie /appointments/login) to /appointments/index.html.我们有一个应用程序位于主要是 javascript 的子文件夹 /appointments 中,我们需要将所有其他 url 参数(即 /appointments/login)重定向到 /appointments/index.html。 WPEngine is discontinuing htaccess rules so I'm hoping we can do this via Redirection. WPEngine 正在停止 htaccess 规则,所以我希望我们可以通过重定向来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM