View Complete Thread
  • Re: URL Rewrite to redirect ONLY .html pages

    Sep 20, 2019 03:26 AM|Jalpa Panchal|LINK

    Hi,

    You could use below url rewrite rule:

    <rule name="HTTPS force" enabled="true" stopProcessing="true">
     <match url="(.*)" />
     <conditions>
                            <add input="{HTTPS}" pattern="off" />
                            <add input="{HTTP_HOST}" pattern="^www.abc.com$" />
                            <add input="{REQUEST_URI}" pattern="(.*)\.html|(.*)\.html|(.*)" />
                            <add input="{REQUEST_URI}" pattern="(.*)\.txt|(.*)\.xml" negate="true" />
     </conditions>
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
     </rule>

    in https you can only use on or off.

    to match the hostname you need to use {http_host} server variable.

    <add input="{REQUEST_URI}" pattern="(.*)\.txt|(.*)\.xml" negate="true" /> this rule deny the txt and xml file to redirect http to https.

    <add input="{REQUEST_URI}" pattern="(.*)\.html|(.*)\.html|(.*)" /> this rule allow html ,htm and other extetion page to redirect http tp https. 

    You could refer this below document for more detail:

    IIS Server Variables

    URL Rewrite Module Configuration Reference

    Creating Rewrite Rules for the URL Rewrite Module

    Regards,

    Jalpa

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.