Azure Websites: Converting .htaccess rewrite rules to the IIS web.config format

Increasingly when using Azure Websites, I'm finding the need to convert .htaccess files provided with PHP websites into web.config files that Azure/IIS understand.

A quick helpful tip, IIS can do this for you (after installing the URL Rewrite extension):

1) Open the IIS Management Console on your local machine. Step 1

2) Open the URL Rewrite section under Default Web Site (or any other Site). Step 2

3) Click on Import Rules... on the right menu. Step 3

4) Paste the contents of your .htaccess file into the Rewrite Rules field. Step 4

5) Create a new web.config file using the following template, filling in the rules with the XML from the XML View.

<?xml version="1.0" encoding="UTF-8"?>
    <!-- Paste rules from XML View here -->

6) Upload this web.config file to the root folder of your Azure Websites PHP site.

You may see warnings when doing the conversion - it's worth checking these manually before using the generated web.config rules. A common example is that RewriteBase is unsupported - IIS treats this a little differently and infers the base URL from the location of the web.config.