Remove .php and .html extensions with web.config on IIS7

Posted: 14th July 2014 by kunwardharmesh in MSSQL

iis7

1. Start IIS Manager and on the left, in the Connections pane, select your required site (e.g. Default Web Site)

2. In the centre (Features View) double click URL Rewrite.

3. In the right panel click Import Rules… then paste your rules from the .htaccess file into the Rewrite rules box

4. 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
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.php $1.html [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>
<rule name=”Imported Rule 2″ stopProcessing=”true”>
<match url=”^(.*)$” />
<conditions logicalGrouping=”MatchAll”>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” />
<add input=”{REQUEST_FILENAME}.html” matchType=”IsFile” ignoreCase=”false” />
</conditions>
<action type=”Rewrite” url=”{R:1}.html” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

  1. Herox San says:

    thank u dude it work, but plz edit this ” with this “