I have these rules set in my Web.config:
<rules>
<rule name="replacedash">
<match url="(.*)(-)(.*)\.aspx$" />
<action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
</rule>
<rule name="extensionless" stopProcessing="true">
<match url="(.*)\.aspx$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" 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}" />
</rule>
</rules>
I've upgraded my website from plain ASP.NET to ASP.NET MVC and I've written these rules just in case there are still some old cached links in search engines with .aspx extensions; however, there are some directories on my web server that still contain .aspx files for good reasons and my rules are rewriting those extensions as well.
How do I exclude these folders from inheriting my rules?
Based on the following solution here:
How to exclude a directory with IIS URL rewriting?
You could do something like this:
<rules>
<rule name="ignore web forms folder 1" stopProcessing="true">
<match url="^webformsfolder1/" />
<action type="None" />
</rule>
<rule name="ignore web forms folder 2" stopProcessing="true">
<match url="^webformsfolder2/" />
<action type="None" />
</rule>
<rule name="ignore web forms folder 3" stopProcessing="true">
<match url="^webformsfolder3/" />
<action type="None" />
</rule>
<rule name="replacedash">
<match url="(.*)(-)(.*)\.aspx$" />
<action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
</rule>
<rule name="extensionless" stopProcessing="true">
<match url="(.*)\.aspx$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" 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}" />
</rule>
</rules>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With