5

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!)

2
  • 1
    Provided you need only redirect requests for the start page (i.e., not for some sub-urls), you might prepend the index page with a script snippet that exaimines the HOST header, and if it is found in your list of SSL-enabled sites, redirects there ...? Commented Jul 12, 2018 at 12:28
  • A script snippet or other similar solution would not work very well for other resources like images. It would mean that I'd have to filter every request. Commented Jul 12, 2018 at 20:50

1 Answer 1

4

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.

1
  • 1
    This I knew already, but it redirects all the domains for the site to HTTPS, which I don't want. I would then need a second site for all HTTP domains. I need a redirect-if-SSL solution on a single site. Commented Jul 21, 2018 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .