3

I have a WordPress website and it has almost 22,000 blog posts. It has been running with good SEO for the past 6 years. The contents are scattered in almost all social media and backlinked in a lot of websites. I also have data in Google Analytics that I would like to preserve.

I'm planning to start a fresh news aggregator site at the base directory of the domain. I want to move the old blog contents to the subdirectory i.e. /blog. I want to run the same old blog in it without affecting the SEO.

I tried implementing 301 redirects in .htaccess, but they are not working the way I want. This is my blog URL pattern /2015/01/10/post-title/ and I tried with this 301 redirection code in .htaccess:

Redirect 301 / http://www.example.com/blog

However, it is redirecting all URLs of the aggregator site which I'm currently running under www directory.

2
  • 1
    Hey I hope you gonna redirect entire blog URLs to subfolder and also you gonna come up with new site in home directory in that case / 301 won't work, You have to manually redirect all the URLs to subfolder. Nov 30, 2019 at 8:49
  • @gokulkarthick Not necessarily, providing the new URLs in the root don't also follow the same "blog" URL pattern: /2015/01/10/post-title/.
    – MrWhite
    Sep 1, 2020 at 16:08

1 Answer 1

1

This is my blog URL pattern /2015/01/10/post-title/

You need to specifically check for the old URL pattern, otherwise you will naturally redirect everything, including all the new URLs of the "news aggregator site".

Try, something like the following instead, at the top of your .htaccess file:

RewriteEngine On

RewriteRule ^\d{4}/\d\d/\d\d/[\w-]+/$ /blog/$0 [R=301,L]

This specifically checks for URLs of the form /2015/01/10/post-title/ and 301 redirects to /blog/2015/01/10/post-title/.

$0 is a backreference that contains the entire URL-path that is matched by the RewriteRule pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.