Moving a WordPress Blog to Windows Azure – Part 4: Pretty Permalinks and URL Rewrite rules

We’re down to the last few, albeit most important, steps in this little project.

In Part 1, we created a new WordPress site hosted on Windows Azure. Part 2, we transferred the content from our old site to the new one. With Part 3, we set up our custom domain with some DNS wizardry.

In this fourth step, I’m going to walk through the steps to make sure my custom permalinks are handled correctly in Windows Azure.

As with most blogs, I want to have “pretty permalinks”. I’m opting for something like http://mysite.com/2013/07/10/my-blog-post-entry over the less friendly http://mysite.com/?p=123. Chances are your permalinks are configured just the way you want them. After all, your entire existing WordPress site options and configurations were moved over as part of the data content transfer in Part 2.

However, if you’ve elected to go with any custom permalink format in WordPress other than the default, you’re going to need to set up some URL Rewrite rules.

Although your WordPress site hosted on Windows Azure is running PHP, it’s running PHP on an instance of Internet Information Server (IIS). Setting up URL Rewrite rules on an IIS server is slightly different than modifying an .htaccess file on an Apache instance.

URL Rewrite rules are defined in the web.config file in IIS.

That’s right. Even though we’re running an PHP website, web.config is still utilized for any server configuration items, including URL Rewrite rules.

Open up your favorite text editor and create a ‘web.config’ file with the following contents:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name=”Main Rule” stopProcessing=”true”>
                    <match url=”.*” />
                    <conditions logicalGrouping=”MatchAll”>
                        <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
                        <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />
                    </conditions>
                    <action type=”Rewrite” url=”index.php” />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Save the ‘web.config’ file and upload it to the root folder of your WordPress application. For my purposes this is the same location for the root of my website as well. As stated in Part 2, an easy method to upload files to your website is through FTP. The FTP HOST NAME and DEPLOYMENT / FTP USER information is available on the website’s dashboard in the Windows Azure Management Portal. You may have to reset your FTP login credentials if you haven’t already done so. You can do this by clicking on the ‘Reset your deployment credentials’ link on your websites Dashboard page.

More information on creating this URL Rewrite rule is available on the IIS Product site.

Assuming you have custom permalinks for your website, you should be up and running with your WordPress on Windows Azure now. CONGRATULATIONS!

However, that’s not the end of this article series. I chose to take a big leap during this transition to running my WordPress blog on Windows Azure to finally removing my blog off of a subdomain (http://davebost.com vs. http://davebost.com/blog). We’ll cover that adventure next.

Categories: Azure
  • http://jeftek.com Jef

    Thanks Dave! I was looking for this exact thing after moving from a Linux to the Azure host. BTW – If you add the Website from the Gallery, it sets up the Web.config for you with these settings by detault now.