0
votes

I had my wordpress website under a folder inside my domain root http://example.com/oldfolder/. Now I have changed the wordpress folder's name to http://example.com/newfolder/ and I need to create redirects for my posts which were shared on facebook because on Facebook they point to http://example.com/oldfolder. I need to create a redirect so that if a user click on the facebook post it redirects him from http://example.com/oldfolder/index.php/post-category/the-post-tile/ to http://example.com/newfolder/index.php/post-category/the-post-tile/

I have tried the following redirect rules:

  1. Redirect 301 /oldfolder/ http://example.com/newfolder/
  2. RewriteRule ^/oldfolder/^(.*) /newfolder/$1 [L,R=301]
  3. RedirectMatch 301 /oldfolder/^(.*) /newfolder/$1

But none of the above worked. I installed the WP redirection plugin but it also didn't work.

Could some please tell me how properly set up the redirect rules?

Thank you!

2
check your .htaccess file, i think it has still the old name - V5NEXT

2 Answers

0
votes

You almost had it with number 2 - the condition checked against starts after the / in the URL so you need to leave that off the start like so:

RewriteRule ^oldfolder/(.*) /newfolder/$1 [L,R=301]

Demo: http://htaccess.mwl.be?share=4e06922b-9f70-5c5b-af8c-cf6544eb984d

EDIT: Oh yeah, and ^ only has special meaning at the start of a regex, where it anchors it to the start of a string, or to negate a character class so inside [] like so, for example: [^az], which reads "match a character not 'a' or 'z'".

0
votes

Maybe you could try this:

RewriteEngine On

RewriteRule ^oldfolder/index\.php/(.*)/(.*)$ http://yoursite.com/newfolder/index.php/$1/$2 [R=301,L]