When looking at moving my blog from a sub directory to the root directory of my site I did a bit of searching. Most of the guides seemed a bit long winded for my liking as most of them covered moving a site hosted in all different environments. As my site is hosted in Microsoft IIS I found I was picking sections out and having to piece together a solution myself. This won’t help everyone as some setups are a little more complicated than mine but have a read through anyway as it should work in most situations.
I wanted to move my site from being in a sub directory which was www.cracknells.info/blog to being in the root of my site (www.cracknells.info). At first this seemed simple enough but would require a bit of forward thinking. After trawling through a few guides I managed to work out a solution. The very first thing to do which is always good practice when attempting anything this major is to take a backup of your site and storing it in a safe place. This includes backing up the files in the current directory which for me was www.cracknells.info/blog and also taking a backup of the SQL database. Depending on your setup and level of access this can be done a few ways. I have physical and full access to my servers so I could just remote into the desktop and copy and paste the files from the sub directory to a safe location. If you don’t have this option it is just as easy to do it using an FTP connection and downloading a copy of the current WordPress directory.
As for the SQL database just as I did with backing up the files I just remoted into the server, I am using Microsoft SQL to store my database so I just loaded up the management studio, logged in and took a backup. However if you use MySQL this can be done with phpmyadmin or even command line if you have access.
After you move your site you will find that all the links to your images will be broken as they will be pointing at the old URL. You can update these manually which is fine if you have a small site. However there is a much simpler method which is to download a plug-in which can do it for you. So before you move your site, first login to your WordPress site and go to ‘Plugins’. Next click ‘Add New’ and search for ‘Velvet Blues Update URLs‘.
So next we need to update the URL’s of your current site so that they correspond with the URL’s of the new location e.g. change from www.example.com/blog to www.example.com.
The next thing to do is physically move the site. So in my case I remoted back in to my server and cut all the files and folders from in the sub directory (www.cracknells.info/blog) and pasted them into the new directory (www.cracknells.info). Like I said before if you don’t have this access to your site it is just as easy to use FTP to move the files. Once you have moved all the files and folders over you can remove the old sub directory in which the blog used to reside.
Now if you visit the site in its new location you should find all looks well. However any images you click on will come up with a 404 error as the links to these files are still wrong. So next you need to login to your site to correct this. You may find you have to use www.example.com/wp-login.php to access the login page. Once you have logged in go to Settings > Update Url’s.
Remember that plug-in you installed earlier? This will do the hard work for you. Just fill in your old URL which for me was www.cracknells.info/blog then fill in your new URL which again for me was www.cracknells.info and make sure you tick the top 4 boxes so that everything in your site is updated and click ‘Update URLs NOW’. You should find now if you visit your site all images, links and pages will be working as they did before.
And that’s it! You may find you have to update any manual links you have entered and its worth reviewing your Permalinks to check that your preferred layout is still selected. Some plug-ins require you to manually update the URL’s, I had this with a plug-in I use to display social media share buttons. However some may require the plug-in to be reinstalled to fix this issue.