IIS Windows .htaccess mod_rewrite

If you have GoDaddy IIS7 windows hosting and you need to get some mod_rewrite action happening, you need a file called web.config uploaded to the root directory (where all your website files are stored)

Here is the .htaccess mod_rewrite rules I was trying to get working on IIS7 

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/webitor/api.*
RewriteRule ^(.*)$ /webitor/webitor_api.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,QSA]

Here’s the web.config version of these htaccess rules which worked on GoDaddy:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <identity impersonate="false" /> 
  </system.web>
  <system.webServer>
    <rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{URL}" pattern="^/webitor/api.*$" ignoreCase="false" />
      </conditions>
      <action type="Rewrite" url="webitor/webitor_api.php" appendQueryString="true" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^/webitor/api.*$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.php" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>
    <directoryBrowse enabled="false" />
  </system.webServer>
</configuration>

Leave a Reply

Your email address will not be published. Required fields are marked *