Toolie
Toolie

Reputation: 1

Moving Wordpress blog from subdirectory to root with 301 Redirect, and with other pages in htaccess

This question is very similar to Redirect subdirectory of old domain to root folder of new domain via htaccess but that one is not a complete answer for me, so here goes:

What I need are the lines that will redirect any blog posts from the old location to the new location, something like:

RewriteCond %{HTTP_HOST} ^olddomain\.com [NC] [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com [NC] 
RewriteRule ^blog/(.*)$ olddomain.com/$1 [R=301,L] 

Will these work? Where do they need to be in the file if there are other 301 statements for unrelated domains?

Toolie

Upvotes: 0

Views: 939

Answers (1)

Phil Perry
Phil Perry

Reputation: 2130

You need to do this redirecting of old stuff before you turn Wordpress's SEO stuff loose on it.

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^(www\.)?olddomain\.com [NC]
RewriteRule ^blog/?(.*)$  /$1  [R=301,L]

How many domains are involved? Is it all under this one domain? In that case, you don't need to check the HTTP_HOST and can omit the RewriteCond. R=301 tells search engines to update their indexes (and users to re-bookmark the site).

You've already done the work, but I'll repeat what I always say about moving existing installations: Don't. Put major applications and subsystems in their own directory tree, and either URL rewrite if it's the only application, or put a custom landing page in. The most important gain is that other applications (future) won't have to pass through Wordpress's .htaccess.

Upvotes: 0

Related Questions