pinoy_ISF pinoy_ISF - 3 months ago 16
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:

<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!

Answer

Change your action to:

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

Note the appendQueryString="false" attribute :)

Comments