Avatar of crp0499
crp0499
Flag 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
Microsoft IIS Web Server

Avatar of undefined
Last Comment
crp0499

8/22/2022 - Mon
zc2

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

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.
zc2

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
crp0499

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

ASKER
you said web.config….my bad...
David Johnson, CD

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
David Johnson, CD

htaccess is for apache web server
web.config is for iis web server
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.
David Johnson, CD

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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.
zc2

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
crp0499

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.