大网数据广告活动
服务器运维问答

How to redirect some sites from HTTP to HTTPS in IIS

· 52CE 我爱测

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. Tho…

问题原文

原帖链接 · Wim ten Brink · CC BY-SA 4.0

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

已采纳解答

原帖链接 · LukeBurke_PremierEPOS · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。