IIS Redirect – How to Redirect Some Sites from HTTP to HTTPS

iisssl

As a software developer I have a simple web server (Windows 2012/IIS) which I use for two different domains. In general, I have a basic "Default" site as a catch-all and various other sites for specific domains or subdomains. Those specific sites are projects that I'm working on while the default site is just a generic toolbox. My question is about redirecting just some domains to HTTPS on this default site!

So I use a Let's Encrypt SSL certificate for this default site and 'Certify the Web' to keep the certificate uptodate. Works fine, as long as I bind the specific domain name to this site. But as I said, it is a catch-all site so I might have bound example.com but www.example.com or my.example.com are unbound. And as there are many other subdomains possible, I tend to have way more pages without SSL than with SSL. Which is fine! No problem.

But when someone goes to the site for a domain that is bound, I want them to be redirected to the secure site instead. So if they visit http://example.com they would end up at https://example.com. And while I could force IIS to redirect all requests to the secure version, doing so will result in most of the domains not being found on my server, as they're unbound. So I only want redirections for sites bound to this default site.

There is an alternate solution, which is by creating a second default site. This one would force SSL to be enforced so the bound sites would be secure. But this is a small server for all kinds of projects and I don't want yet another site in the list of 40 sites that I already have. (And this list tends to grow even more.) So I want to know if it is possible to force SSL just for the bound sites while the unbound ones will not be redirected.
(In case you're wondering, there will be some special logic behind the default site and the secure domains will have a login feature for me to handle some additional administrative tasks like checking the logs and server health. It's not a simple default site!)

Best Answer

There is a brilliant tutorial at this website here

If you follow this then you should be able to set up the redirect no problem!

This will allow you to set up redirects for any site of your choosing.

Related Topic