When I first made my WordPress site I didn’t know it’s a good idea to use slugs instead of ids in links. I had a page back then that had the address:
http://example.com/?page_id=50
When I made a template for a popular e-commerce platform in my country I included said link. A year later the site crashed and I had to rebuild it. Needless to say, the page in question was assigned with a different ID. I cannot change it on e-commerce platform (that would require thousands of individual changes – that is not an overstatement).
So, can I somehow redirect the /?page_id=50
to a different page? The problem is that no page has this particular ID.
Is there any way? I tried .htaccess redirection but it didn’t work or maybe I did something wrong.
I wrote
Redirect /?page_id=50 http://example.com/page-slug/
in .htaccess
I also tried (as suggested below):
# 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
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)page_id=50($|&)
RewriteRule . http://example.com/page-slug/? [R=301,L]
as well as:
# 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]
RewriteCond %{QUERY_STRING} (^|&)page_id=50($|&)
RewriteRule . http://lucart.pl/lucart-w-radio-eska/? [R=301,L]
</IfModule>
# END WordPress
Neither worked 🙁
Please help.
Please add this redirection php code at the very top of your theme header.php template before the html started:
You can’t use a query string with
Redirect
. You will need to usemod_rewrite
and check for thequery string
.