I have a link like this:
From: http://www.example.com/wp/?p=231
and I need to redirect it to this URL:
To: https://www.example.com/jump/
How could this be done?
This the .htaccess file:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
2
Answers
Depending on your .htaccess file you posted, the solution should be the following:
You can check it with the following link:
https://htaccess.madewithlove.com?share=d5a7976b-47f3-4143-bb7c-103a722f0b2d
You need to use mod_rewrite to perform this specific redirect. And this rule should go at the very top of your
.htaccess
file, before all existing rules. For example:UPDATE: Added the two additional conditions to check the
SERVER_PORT
andHTTP_HOST
so that it only redirectshttp://www.example.com/wp/?p=231
exactly as stated. It then redirects directly tohttps://www.example.com/jump/
.The additional condition that checks against the
QUERY_STRING
server variable is necessary in order to match the query string, since theRewriteRule
pattern matches against the URL-path only.The
QSD
flag is necessary to remove the existing query string from the redirected response, otherwise this is passed through by default.