Daniel Anderson
Daniel Anderson

Reputation: 275

HTTPS Redirect not working quite right

I'm using the following code in my ASP.NET web.config file to redirect "www" requests to my secure web site:

<rewrite>
    <rules>
      <clear/>
      <rule name="httpsredirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{REQUEST_URI}" />
      </rule>
    </rules>
</rewrite>

The goal is to ensure that when someone enters

"http://www.example.com/somepage.aspx"

they get redirected to

"https://www.example.com/somepage.aspx"

.

The problem is that the redirect works just fine in sending them to the secure site, but the destination URI is missing, so they get sent to the site's root default page. Any help here? Thanks! Right now

Upvotes: 1

Views: 52

Answers (2)

Gavin
Gavin

Reputation: 4515

If you check out the answer here, you'll see that they have url="https://{HTTP_HOST}{REQUEST_URI}" as opposed to your url="https://{HTTP_HOST}/{REQUEST_URI}".

Upvotes: 1

VDWWD
VDWWD

Reputation: 35514

Try changing

<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{REQUEST_URI}" />

To

<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />

Upvotes: 1

Related Questions