pinoy_ISF pinoy_ISF - 1 year ago 102
ASP.NET (C#) Question

IIS Rewrite Rule Redirect HTTP to HTTPS causes multiple RedirectURL querystring

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

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

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

h t t p://

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://

How to handle this case? Thanks in advance!

Answer Source

Change your action to:

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

Note the appendQueryString="false" attribute :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download