HTTP redirect to HTTPS

crp0499
crp0499 used Ask the Experts™
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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

crp0499CEO

Author

Commented:
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.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

crp0499CEO

Author

Commented:
My .htaccess file was empty so I pasted that code, restarted IIS and still no joy.
crp0499CEO

Author

Commented:
you said web.config….my bad...
Top Expert 2016
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

Top Expert 2016
htaccess is for apache web server
web.config is for iis web server
crp0499CEO

Author

Commented:
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.
Top Expert 2016
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
crp0499CEO

Author

Commented:
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?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial