Moving a WordPress Blog to Windows Azure – Part 5: Moving From a Subfolder to the Root

In Part 1, I created a new WordPress site hosted on Windows Azure. In Part 2, I transferred all of the relelvant content from my old WordPress site to my new one hosted on Windows Azure. In Part 3, we made the necessary configuration changes from my domain registrar to Windows Azure to have my custom domain ( direct people to my new blog site on Windows Azure. In Part 4, I had to define some URL Rewrite rules with a web.config file to handle my custom permalinks in my WordPress blog.

In Four (somewhat) short steps, I’ve completely moved my WordPress blog over to Windows Azure! However, I’m not done yet. As part of this transition, I made the decision to finally move my blog off of a subfolder off of my site ( to the root of my domain (

This made me nervous as I imagined all of the links scattered across the Interwebs that I’ve built up for the past 10 years suddenly blowing up. However, with a little plug-in magic and a new URL Rewrite redirection rule I was able to finally check off this task that’s been on my list for several years!

The Database Search/Replace Magic


WARNING! Before you do anything, make sure you have a backup of your WordPress site and WordPress database. See WordPress Backups on steps on how to protect yourself. I am not responsible for any catastrophic events that may take place.

The good news is you are migrating from an existing site, so you should be covered. Plus, short of completely deleting  your database without a backup, any changes made should be easily remedied. But…you’ve been warned!

My WordPress content database is littered with relics of the past. Namely various references to my old blog address ( From various WordPress configuration settings to my post content as well. The recommended approach found within the Moving WordPress documentation is to search all references of the past and replace with the new. According to this document, there are no less than 15 (!) steps to accomplish this task. Thankfully, the great folks over at interconnect/it have created a Search and Replace for WordPress Databases Script to accomplish this feat for us.

Download the script zip file.

If you’re running Windows, I recommend ‘unblocking’ the zip file once it’s downloaded and before you unzip it. Open up Windows Explorer and navigate to the folder containing the downloaded zip file. Right-click on the zip file name and select properties. On the ‘General’ tab, click the ‘Unblock’ button and click ‘Ok’.

Unzip the file and upload the ‘searchreplacedb2.php’ script file to the root of your WordPress site.

Some helpful steps on how to upload files to your WordPress site using FTP can be found in Part 2 and Part 4.

Run the script by opening your favorite web browser and navigating to the location of the script file (ie.


Click the ‘Submit’ button to have the script retrieve your database connection strings as defined in your wp-config file.

On the ‘Tables’ step, I kept the defaults and selected Continue.

For my purposes, I chose to replace the following on the ‘What to replace?’ step:


Thankfully, I didn’t encounter any errors:


Don’t forget that once the script is finished running to DELETE THE SCRIPT FILE FROM YOUR SITE!

After a cursory scan of my blog content, everything seems to be in working order!

Handling 301 Redirects with a URL Rewrite Rule

Now that my site content has been updated with the new permalink content, what about all of those hanging links to my content scattered across the Internet. Are they forever broken? Thankfully, with a little URL Rewrite magic, they’re not. The recommended approach to notify the various search engines of this change and handle the redirection from existing links is to use a 301 Redirect.

To handle this for my purposes, I added a Redirect rule to my <system.webServer> configuration section in my web.config file:

         <rule name=”RedirectRule” stopProcessing=”true”>
             <match url=”^blog/?(.*)$” ignoreCase=”true” />
             <action type=”Redirect” url=”{R:1}”
                         redirectType=”Permanent” />

Setting ‘redirectType’ to ‘Permanent’ identifies this as a 301 Permanent Redirect. In short, the match regular expression looks for the string ‘blog’ within the url, captures everything following ‘blog/’ and replaces {R:1} with the contents in the <action> element. My rule defined in Part 4 for handling the custom permalinks in my WordPress site follows this RedirectRule definition.

WE DID IT! In a few short steps we migrated a WordPress site over to Windows Azure with a couple of additional tweaks required for my particular purposes to move from a subfolder to the root of my domain. FINALLY!

What I’ve learned is that within a matter of a minute or so, I can stand up a WordPress site on Azure. And within an hour or two, I can migrate all of my data over from my old WordPress site to my new site hosted on Windows Azure.

I hope these instructions were valuable in your pursuit. Let me know how everything turns out in the comments.


Categories: Azure