Link to home
Create AccountLog in
Avatar of crp0499
crp0499Flag for United States of America

asked on

HTTP redirect to HTTPS

I have a web site that I have published.  This is published on my own Windows Server 2019 server.  

When I hit the URL http://mysite.com, it works great.  I can type mysite.com, http://mysite.com, www.mysite.com and it all works like a charm.

I bought an SSL cert, installed it on the server, added the binding and now I need my http to redirect to https.

I've read up on this and I see that there is an HTTP redirect I can install on my IIS server.  

I see I can use IIS URL rewrite (looks intimidating, but I can figure it out).

I see some docs on editing the .htaccess file.

I need the "best" and easiest way to do this.  I prefer simple and I prefer to use the tools Microsoft has versus jumping thru a million hoops or having to have a PhD in IIS, so, if you please, guide me in my endeavor.

Thanks

Eric
Avatar of zc2
zc2
Flag of United States of America image

I would use the URL rewrite feature.
Here is a sample rule which redirects GET requests to HTTPS :
 <rule name="Force HTTPS" enabled="true" stopProcessing="true">
     <match url="(.*)" ignoreCase="false" />
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="off" />
                        <add input="{REQUEST_METHOD}" pattern="GET" />
     </conditions>
     <action type="Redirect" url="https://mysite.com{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>

Open in new window

Avatar of crp0499

ASKER

So, that's code.  Do I paste that in somewhere or write a rule that matches that?  From what I see, the URL rewrite is more of a "complete the conditions" feature versus pasting code.
Yes, you could paste it to your site's web.config file. But if you don't have one, I'd suggest you just to use the IIS URL rewrite UI and create your own rule based on the attributes of the XML I posted.
Avatar of crp0499

ASKER

My .htaccess file was empty so I pasted that code, restarted IIS and still no joy.
Avatar of crp0499

ASKER

you said web.config….my bad...
First can you access your site via https://www.yourdomain.com ? This is to check that the bindings are set correct. To have url rewrite work you need to have the module loaded. htp-redirection.
powershell
add-windowsfeature Web-Http-Redirect

Open in new window

htaccess is for apache web server
web.config is for iis web server
Avatar of crp0499

ASKER

David, I cannot access the site using https://www.mydomain.com. even if I put in the index page I can’t access it that way. the cert is correct with the binding though.
you can access it if  in iis you use the browse website option and select the :443 site? you will get a certificate error but you can disregard this.. if this works then check your router to ensure that port 443 tcp is set to forward to your computers local ip address
Avatar of crp0499

ASKER

From within IIS, I cannot browse it on 443.  I can browse it on port 80 though.\

I have verified the cert.  It is correct.

Interesting.  I'm using hostnames, so I added 443 to the default site and I can browse it just fine on 443.  I think I'm going to remove and readd the 443 bindings.

That didn't fix it.  I removed and readded the 443 bindings and attached the cert and no joy.

The default web site, the one that's created when IIS is installed...I can add a 443 binding to that site and browse it.  If I create additional sites and add 443 binding, I cannot browse it from within IIS.
How do you bind the additional sites? By a separate IP address or just the site name? If the second do you have the "Server Name Indication" checkbox on?
ASKER CERTIFIED SOLUTION
Avatar of crp0499
crp0499
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account