I have a link like this:
From: https://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?
CodePudding user response:
You need to use mod_rewrite to perform this specific redirect. For example:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=231$
RewriteRule ^wp/$ /jump/ [QSD,R=302,L]
The additional condition that checks against the QUERY_STRING server variable is necessary in order to match the query string, since the RewriteRule 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.
If you have existing directives in the .htaccess file then the order of directives is important. This redirect likely needs to go near the top of the file, before any existing rewrites.
EDIT: Since you've tagged the question "WordPress", you need to place this rule before the # BEGIN WordPress section. You do not need to repeat the RewriteEngine On directive.
CodePudding user response:
You can solve it that way:
RewriteEngine on
RewriteRule ^wp/.*$ /jump [R=301,NC,L]
The parameters will be included at the end of the new URL. If you meant to redirect the whole exact URL (WordPress post) to the new location, you could just use the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/wp/$ [NC]
RewriteCond %{QUERY_STRING} p=231
RewriteRule (.*) /jump [R=301,NC,L]
