简体   繁体   中英

IIS Rewrite Rule Redirect HTTP to HTTPS causes multiple RedirectURL querystring

We're using this rule to redirect HTTP to HTTPS:

<rewrite>
    <rules>
        <rule name="Redirect HTTP to HTTPS" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="SeeOther" />
        </rule>
    </rules>
</rewrite>

This works fine but when a user has bookmarked a URL like this:

h t t p://www.mysite.com/myapp/login.aspx?ReturlURL=/someurl

It redirect them to HTTPS as expected but with 2 ReturnURL querystring which causes a 404 error when they login:

h t t p s://www.mysite.com/myapp/login.aspx?ReturnURL=/someurl&ReturnURL=/someurl

How to handle this case? Thanks in advance!

Change your action to:

<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" appendQueryString="false" redirectType="SeeOther" />

Note the appendQueryString="false" attribute :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM