Search code examples
htmlasp.netweb-config

What is Rewrite Html tag in web.config


I found this line of code in my web.config, and I cannot understand what does it exactly do for my website. What is the need of this in my web.config?

<rule name="RewriteHTML">
          <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">                     
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                     
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                 
            </conditions>                 <action type="Rewrite" url="{R:1}.html" />             
</rule> 

Solution

  • You have a rule named "RewriteHTML" (that's up to you).

    The match element is the pattern you want to match (regular expression). In your case, you match everything.

    If you want to test Regex: https://regex101.com/

    The action element tells what should be done with request that match the pattern. The type Rewrite tells that the request should be rewritten to another URL.

    The conditions in this case tells to not match requests to files or directories.

    So what happens is that you add ".html" to all your incoming requests.

    For more clarification on {R:1} notation: IIS URL Rewrite {R:N} clarification