Search code examples
asp.netiisurl-rewritingasp-classicweb-config

Webconfig URL Rewrite to Hide Classic ASP ext but not .aspx or other ext


I have been able to hide the .asp extension, but it also removes any other extensions and points to .asp I know this is just a config issue but have no experience of the webconfig file configuration and wonder if anyone has a quick solution to save me a few hrs! Code as I have it below from part of webconfig file

<rewrite>
  <rules>
    <rule name="Hide .asp Ext">
      <match url="^(.*)$" ignoreCase="true" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_FILENAME}.asp" matchType="IsFile" />
        </conditions>
        <action type="Rewrite" url="{R:0}.asp" logRewrittenUrl="true" />
      </rule>
      <rule name="Redirect .asp Ext" stopProcessing="true">
         <match url="^(.*).asp" ignoreCase="true" />
           <conditions logicalGrouping="MatchAny">
            <add input="{URL}" pattern="(.*).asp" />
           </conditions>
           <action type="Redirect" url="{R:1}" />
       </rule>
  </rules>
</rewrite>

Solution

  • Try this? Seems to work on my test server.

            <rule name ="redirect .asp to none" stopProcessing="true">
                <match url="(.*)\.asp$" />
                <action type="Redirect" url="{R:1}" redirectType="Permanent" />
            </rule>                  
            <rule name="hide .asp extension" stopProcessing="false">
              <match url="(.*)" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="{R:1}.asp" />
            </rule>