Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: 301 redirect in .htaccess - old URL includes ?page_id I want to 301 redirect several URLs from an old WordPress installation within one subdirectory to a new WP installation within a different

@LarsenBagley505

Posted in: #Htaccess #Redirects

I want to 301 redirect several URLs from an old WordPress installation within one subdirectory to a new WP installation within a different directory of the same domain. I.E.:
www.example.de/abc/?page_id=123

needs to go to:
www.example.de/xyz/newindividualpage/

I have tried several options I found here and elsewhere, but so far I was unable to get it to work, resp. adapt found code correctly to my needs. Obviously the ?page_id= structure is where I am missing it.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

3 Comments

Sorted by latest first Latest Oldest Best

 

@Berryessa370

#Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ example.com/ [r=301,nc]


You can also migrate your Wordpress posts using Wordpress Plugins wpclone by wp academy.

10% popularity Vote Up Vote Down


 

@Candy875

You could also just install the excellent WP Redirect plugin that will make for a quick fix.

10% popularity Vote Up Vote Down


 

@Ogunnowo487

In order to match the query string (ie. page_id=123 part) you need a RewriteCond directive and the QUERY_STRING server variable (from mod_rewrite). Try something like the following in the /abc/.htaccess file (ie. in the subdirectory you want to redirect from):

RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=123
RewriteRule ^$ /xyz/newindividualpage/ [R=302,L]


(Change the 302 to 301 when you are sure it's working OK. 302 (temporary) redirects aren't cached by the browser, so makes testing easier.)

This redirects any URL within the /abc subdirectory that has a query string that starts page_id=123 (as per your example).



Alternatively, if you prefer to only use the .htaccess file in the document root, then add the following to the top of the .htaccess file (at least before any other mod_rewrite directives) in the root directory:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=123
RewriteRule ^abc/?$ /xyz/newindividualpage/ [R=301,L]


The RewriteEngine directive only needs to appear once in the file. It can appear anywhere in the file, although it is more logical if it appears at the top. (It doesn't matter if it occurs more than once, it's just unnecessary.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme