Everything works fine and the file name is returned as http://www.mysite.com/folder/filename instead of
http://www.mysite.com/folder/filename.htm
However, I have many URLs to rewrite in the same way as above and I reached a limit of URLs over which IIS doesn’t allow me to add more URLs.
The question is: is there a way I can manage this with wildcards or programmatically, that is by adding a single and simple rule which allows me to remove all the
.htm extensions to all my URLs?
Claudio7810
Member
57 Points
89 Posts
URL Rewriting - Remove all .htm extensions
Nov 16, 2011 06:47 PM|LINK
Hi All,
I d like to remove all the .htm extensions off from my URLs and tried with IIS friendly rule which rewrites the URL using the following code:
<rule name="filename" stopProcessing="true"> <match url="^folder/filename$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="folder/filename.htm" /> </rule>Everything works fine and the file name is returned as http://www.mysite.com/folder/filename instead of http://www.mysite.com/folder/filename.htm
However, I have many URLs to rewrite in the same way as above and I reached a limit of URLs over which IIS doesn’t allow me to add more URLs.
The question is: is there a way I can manage this with wildcards or programmatically, that is by adding a single and simple rule which allows me to remove all the .htm extensions to all my URLs?
Thanks in advance
rewrite
Claudio7810
Member
57 Points
89 Posts
Re: URL Rewriting - Remove all .htm extensions
Nov 19, 2011 08:18 AM|LINK
I got it
this is the sample code:
<rule name="remove htm extensions"> <!--Removes the .htm extension for all pages.--> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).htm" /> </conditions> <action type="Rewrite" url="{R:1}.htm" /> </rule>rewrite