Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

IIS help - redirecting single page to HTTPS

NekkiNekki Veteran
edited October 2015 in Help

IIS is a massive pain in the arse.

I need to redirect a single page to the HTTPS version. Try as I might, I don't seem to be able to do this. I'm sure it's because I'm being vaguely stupid, but I've been looking at it for 2 hours now and can't work out the issue.

I'm trying to do this via the URL Rewrite module - basically I need just the page http://www.domain.com/path/to/content to redirect to https://www.domain.com/path/to/content - results so far vary from absolutely nothing happening to a reboot loop.

Currently code looks something like this:

< rule name="HTTP to HTTPS" stopProcessing="true" >
    < match url="(*./content$)" / >
    < conditions >
         < add input="{HTTPS}" pattern="off" / >
    < /conditions >
    < action type="Redirect" url="https://{HTTP_HOST}/{R:0}" / >
< /rule >

Which causes the redirect loop.

Halp.

Comments

  • Nekki said: I need

    ...

  • Hit enter too early.

  • I just did a quick google and came up with

          <rules>
            <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
              <add input="{SERVER_PORT_SECURE}" pattern="^1$" />
              <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/OWA/" redirectType="Permanent" />
            </rule>
          </rules>
    

    Looks slightly different from yours so it's worth a shot? (I have no experience with IIS so this is just a random guess)

  • wychwych Member
    edited October 2015

    Just throw the whole site under SSL?

    Do you have to do it via web.config? You could just use (not tested a hacked draft) on the page (assuming ASP).

            if (HttpContext.Current.Request.IsSecureConnection)
            {
                MessageBox.Show("I am Running on Port 443");
                // do something on ssl?;
            }
            else
            {  MessageBox.Show("I am Running on Port 80");
    Response.Redirect "https://yourdomain.com/page";
            }
    
  • NekkiNekki Veteran
    edited October 2015

    wych said: Just throw the whole site under SSL?

    Ideally that's exactly what I'd do, but it's not possible in this instance.

    wych said: Do you have to do it via web.config?

    Yes, I don't have access to the content. I need to be able to do this via the server.

    EDIT: strictly speaking, I'm using rewrite maps, not writing directly to web.config. I don't think that makes a difference, but then IIS is a prick so who knows.

Sign In or Register to comment.