I was planning to move my wordpress blog to a new subfolder instead of the current root folder. I had to go through a long process. I did some research and found a few wordpress plugins that will do the job for me but my situation was a little different. I wanted to move all wordpress php files to a subfolder like /blog and also the main blog permalinks.

I read on google webmasters tools website that if you put a permanent redirect (HTTP 301) for your old indexed URL the google bot will update its index with the new URL gradually. Since I just started writing blog I had only about 21 URLs indexed in google but I still dont want to lose those !

Here is what I did to achieve this. ( I am warning Try at your own risk)

First in WordPress that is a way to change the blog url and wordpress url so I changed both to http://www.vaibhavbora.com/blog. As soon I made this change I anticipated that my control panel will not work but I can easily get it back my moving wordpress files. I created a new folder under my root folder called “blog” and moved all of the wordpress files using Filezilla. Except a few files like robots.txt, sitemaps.xml which are not related to wordpress etc. Remember you might has a .htaccess file that wordpress created for you or modified, you have to move this file also. Once everything was moved I got my admin back and to my wonder everything worked perfectly ! All my blog links now had /blog as the prefix folder name.

Next I had to make sure my old URL links work. It is important since people visit my blog from google and bing and I don’t want them to see a 404 or file not found error. I did bing search and found a few tips. I already had some idea that I have to use mod_redirect and put some rules in my .htaccess file to redirect old valid URL to new location which is now in a sub folder.

Remember earlier I had said that we have to move the .htaccess that was in the root folder to the blog folder to make wordpress work (this may not be true for everyone if you are not using .htaccess based features that wordpress activates.) Now I have to put new rules in my .htaccess file in the root folder. With the following few lines  I was able to achieve this:

# BEGIN OLD Index URL Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^blog/
RewriteRule (.*)$ /blog/$1 [R=301]
</IfModule>

# END

Basically the above code just redirects any URL that doesn’t start with a /blog/ so this will redirect my old indexed URL like http://www.vaibhavbora.com/2009/09/ to http://www.vaibhavbora.com/blog/2009/09/

Above code also makes sure that direct files or folder are not sent to the redirect. This is useful for files like http://www.vaibhavbora.com/robots.txt which don’t contain the sub-folder /blog and should not be redirected to /blog/robots.txt. The –f and –d conditions prevent this.

I will update my post again when I confirm if googlebot is actually replacing my old URL with these new URL by using the HTTP 301 redirect.

I hope many people are in similar situations and will find this blog useful. If you need help or something is not clear do feel free to comment on this post. I will happily reply back. Remember it is very tricky process and may take your site down.

 

Leave a Reply