您需要URL重写模块,最好是v2(我没有安装v1,因此不能保证它会在那里工作,但是应该可以)。
这是此类web.config的示例-它将对所有资源强制使用HTTPS(使用301永久重定向):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
此特定解决方案与ASP.NET/PHP或任何其他技术无关,因为它仅使用URL重写模块完成-它在初始/较低级别之一中进行处理- 在请求到达您的代码之前被执行。