1

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

VDWWD
  • 35,079
  • 22
  • 62
  • 79
Daniel Anderson
  • 275
  • 3
  • 16

2 Answers2

1

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}" />
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • Oddly enough, that did it. I tried it earlier without luck. Maybe I had something narfled in my string (I just copied and pasted yours!). Thank you much! – Daniel Anderson Oct 22 '16 at 14:10
1

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}".

Community
  • 1
  • 1
Gavin
  • 4,365
  • 1
  • 18
  • 27