6

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?

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
thetipsyhacker
  • 1,402
  • 4
  • 18
  • 39

1 Answers1

14

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>
Community
  • 1
  • 1
dana
  • 17,267
  • 6
  • 64
  • 88