I found that IIS7 and above can import Apache.htaccess rules using the Rewrite URL module.
- Install Rewrite URL Module through Microsoft Web Platform Installer
- Launch IIS Manager and on the left, in the "Connections" panel, select the desired site (for example, the default website).
- In the center (view of functions), double-click the URL Rewrite .
- In the right pane, click Import Rules ... , then paste your rules from the .htaccess file into the Rewrite Rules box
- In the right column, click Apply.
In the specific question above, the following .htaccess redirection 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>
source share