I'm using the WordPress Redirection plugin to redirect old landing pages to a new domain.
I'm able to match URLs including any query strings and this redirects 100% to the new domain.
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:
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
It's quite simple, actually.
Just set the Target URL to:
https://new-site.com/page$1
$1
refers to the contents of the captured (\?.+)
in the RegEx you provided.
See https://redirection.me/support/redirect-regular-expressions/ for more details.
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)
http://example.com/page
http://example.com/page/
http://example.com/page?q=test&s=test2
http://example.com/page/?q=test&s=test2