locked
URL Redirect rule in web.config RRS feed

  • Question

  • User-1753299103 posted

    Hi,

    I just started using the following url redirect rule but all links appear to redirect correctly except the ones that come from an email.

    It replaces it as such:

    http://www.mysite.com/te2/35?returnUrl=5    to  https://www.mysite.com/te2/35?returnUrl=5&returnUrl=5

            <rewrite>
                <rules>
                    <rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <conditions logicalGrouping="MatchAny">
                            <add input="{HTTPS}" pattern="off" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>

     

    Friday, February 17, 2017 3:26 PM

Answers

  • User-2057865890 posted

    Hi Engcanada,

    You could update the rule like following.

    <rewrite>
        <rules>
             <rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAny">
                   <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
             </rule>
        </rules>
    </rewrite>

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 20, 2017 6:12 AM
  • User-2057865890 posted

    Hi Engcanada,

    {REQUEST_URI} contains the entire requested URL including query string, so your original rule would end up duplicating query string parameters when redirecting.

    appendQueryString – Specifies whether the query string from the current URL is preserved during substitution. By default, if the value of the appendQueryString flag is not specified, it is assumed to be TRUE. This means that the query string from the original URL is appended to the substituted URL.

    reference:

    https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 21, 2017 7:31 AM

All replies

  • User-2057865890 posted

    Hi Engcanada,

    You could update the rule like following.

    <rewrite>
        <rules>
             <rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAny">
                   <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
             </rule>
        </rules>
    </rewrite>

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 20, 2017 6:12 AM
  • User-1753299103 posted

    I added the following and seems to be working:

    appendQueryString="false" url="https://{HTTP_HOST}{REQUEST_URI}" 

    What exactly is the difference between:

    url="https://{HTTP_HOST}/{R:1}" and url="https://{HTTP_HOST}{REQUEST_URI}" 

    Regards

    Monday, February 20, 2017 3:48 PM
  • User-2057865890 posted

    Hi Engcanada,

    {REQUEST_URI} contains the entire requested URL including query string, so your original rule would end up duplicating query string parameters when redirecting.

    appendQueryString – Specifies whether the query string from the current URL is preserved during substitution. By default, if the value of the appendQueryString flag is not specified, it is assumed to be TRUE. This means that the query string from the original URL is appended to the substituted URL.

    reference:

    https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 21, 2017 7:31 AM