During my early weeks’ training within P2S coaching program, I was taught to make a fresh WordPress installation in /blog directory, rather than the website’s root directory, and have it served from the mentioned directory.
The reason for this is to be able to install more than one WP instances in the same domain, each one in its own directory, for the different products we are going to create.
Well, I already had this rather young IM niche blog and I wanted to reuse it. It already had good posts with good rankings on Google’s first page, most of my actual traffic being from organic search. Even if the traffic was weak, I didn’t want to lose all this starting advantage, so I decided to move the old blog. But it was necessary to devise a strategy for this move.
The following tutorial applies for a Linux hosting account with Apache web server.
The Desired Result
Let’s consider my domain as an example. So, my old blog was accessible at this address:
- www.marketingwithvladimir.com
After the move the address has changed to this:
- marketingwithvladimir.com/blog
I wanted also to get rid of the preceding www because I think it makes the URLs too long. In order to make the move AND not lose all the backlinks and rankings, it was necessary to add some 301 redirects. Keep reading to find out how.
The moving part could be done in 2 ways:
- configure WP in the General Settings admin page for the new path and move the actual WP files to the new location, or
- make a new install with the Softaculous utility from your CPanel in the new directory, export the content from the old, then import it into the new WP instance.
I opted for the second way because I wanted to start over from scratch. So, here are the steps:
The Steps
- Go to the old blog’s Tools->Export admin screen and export the entire content to your local computer. Make sure to remember the location where you save it.
- Go to your hosting CPanel and locate and click on the WordPress installation utility.
- Start a new installation by clicking Install in the upper menu.
- Make sure to change In Directory box content to the desired destination directory, in my case blog.
- Change all other fields to suit your desire. It’s advisable to change the admin username into something else, for example, your name.
- Click Install button.
- After the installation gets finished, point your browser to the back-end of the newly installed blog, domain_name/blog/wp-admin, in my case marketingwithvladimir.com/wp-admin. You’ll have to log in using the credentials you entered during WP installation.
- Go to Tools->Import page and select to import from WordPress. You’ll have to install the WordPress importer plugin. While importing, locate the file created during the export phase.
- Got to Settings->Permalinks page and change to Post name. It is advisable to do this because it makes your blog more friendly for search engines. You can remove the final slash character if you desire, depending on how do you want the posts and pages URLs to look, it’s up to your taste.
Now you can uninstall or delete the old blog.
Add 301 Redirects in .htaccess
Now, if you want to redirect all www.domain_name.com/post_name to domain_name.com/blog/post_name you have to add a few directives in the root .htaccess file.
You may find my root .htaccess here, the relevant part only:
# prevent directory listings
Options -Indexes
RewriteEngine On
# redirect www to non-www and subdir
RewriteCond %{HTTP_HOST} ^www\.marketingwithvladimir\.com$ [NC]
RewriteRule ^(.*) https://marketingwithvladimir.com/$1 [L,R=301]
# redirect non-www root to subdir
RewriteCond %{HTTP_HOST} ^marketingwithvladimir\.com$ [NC]
RewriteRule ^/?$ /blog [L,R=301]
Line 2 is to prevent directory listing.
Lines 5-6 redirect any www-based URLs to non-www ones with the path preceded by the blog’s directory, so that any old URL is globally redirected to its corresponding new URL.
Lines 8-9 redirect any non-www root URL to the same non-www with the blog’s directory appended, so that if you enter only the domain name in the browser, an automatic redirection to the blog’s home page is done.
You can edit the .htaccess file using an FTP utility application.
Update – April 9th, 2015
After moving the blog to the /blog directory I made the necessary changes in Google Webmaster Tools and Google Analytics. After a day or two, the new addresses finished indexing.
Then I checked Google SERP to see the positions of my old posts. After only one more day the new post addresses have replaced the old ones keeping their positions on page one. That was quite a pleasant surprise!
It seems that Google figured out about the move. I suppose that the 301 redirect helped as well.
That being said, I wish you good blogging.
Leave a Reply