Remove File Extension By IIS Rewrite

If you’re running IIS web server and want to remove file extension on website URL such as .aspx .asp or .php etc.. Add following code to web.config

<rule name="RemoveASPX" enabled="true" stopProcessing="true">
    <match url="(.*)\.aspx" />
    <action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
    <match url=".*" negate="false" />
        <conditions>
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
        </conditions>
    <action type="Rewrite" url="{R:0}.aspx" />
</rule>

Share

- has written 121 posts.


Leave a Reply

You must be logged in to post a comment.