I have 3 rules that acted for the basis of 1. Hiding HTML extension 2. Redirecting html 3. non-www to www.

However, this caused 2 301 redirections when user goes to http://example.net/content -> http://www.example.net/content.html -> http://www.example.net/content

<rule name="Hide .html ext">
      <match ignoreCase="true" url="^(.*)"/>
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
        <add input="{REQUEST_FILENAME}.html" matchType="IsFile"/>
      </conditions>
      <action type="Rewrite" url="{R:0}.html"/>
</rule>
<rule name="Redirecting .html ext" stopProcessing="false">
      <match url="^(.*).html"/>
      <conditions logicalGrouping="MatchAny">
        <add input="{URL}" pattern="(.*).html"/>
      </conditions>
      <action type="Redirect" url="{R:1}"/>
</rule>
<rule name="Redirect to www" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example.net$" />
      </conditions>
      <action type="Redirect"
        url="{MapProtocol:{HTTPS}}://www.example.net/{R:1}" />
</rule>

I have a special requirement to only let it do 1 301 redirection for this page. I have tried multiple ways but no results. What is the best way i can try this?

Thank you!

1 Answers

2
napuzba On Best Solutions

Add as second rule :

<rule name="Redirect to www + .html ext" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example.net$" />
        <add input="{URL}" pattern="(.*).html"/>
      </conditions>
      <action type="Redirect"
        url="{MapProtocol:{HTTPS}}://www.example.net/{R:1}" />
</rule>