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"?>
    <identity impersonate="false" /> 
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
        <add input="{URL}" pattern="^/webitor/api.*$" ignoreCase="false" />
      <action type="Rewrite" url="webitor/webitor_api.php" appendQueryString="true" />
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
        <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" />
      <action type="Rewrite" url="index.php" appendQueryString="true" />
    <directoryBrowse enabled="false" />

Leave a Reply

Your email address will not be published.