I have found that IIS7 and above can import Apache .htaccess rules using the URL Rewrite module.
- Install the URL Rewrite module via the Microsoft Web Platform Installer
- Start IIS Manager and on the left, in the Connections pane, select your required site (e.g. Default Web Site)
- In the centre (Features View) double click URL Rewrite.
- In the right panel click Import Rules... then paste your rules from the .htaccess file into the Rewrite rules box
- Click apply in the right column.
In the specific question above the following .htaccess redirect rules
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L]
generate the following web.config file.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Imported Rule 1" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" /> </conditions> <action type="Rewrite" url="{R:1}.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>