如何强制HTTPS使用web.config文件 [英] How to force HTTPS using a web.config file

查看:822
本文介绍了如何强制HTTPS使用web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已搜查周围谷歌和计算器试图找到一个解决的办法,但他们似乎都涉及到ASP.NET等。

I have searched around Google and StackOverflow trying to find a solution to this, but they all seem to relate to ASP.NET etc.

我通常在我的服务器上运行Linux,但为这一个客户我使用Windows与IIS 7.5(和Plesk 10)。这是为什么我的与IIS和web.config中稍微陌生文件的原因。在的.htaccess 文件,你可以使用重写条件来检测该协议是HTTPS,并相应地重定向。是否有一个简单的方法此使用web.config文件,甚至使用实现 URL重写我已经安装的模块?

I usually run Linux on my servers but for this one client I am using Windows with IIS 7.5 (and Plesk 10). This being the reason why I am slightly unfamiliar with IIS and web.config files. In an .htaccess file you can use rewrite conditions to detect whether the protocol is HTTPS and redirect accordingly. Is there a simple way to achieve this using a web.config file, or even using the 'URL Rewrite' module that I have installed?

我的与ASP.NET没有任何经验因此,如果这是参与的解决方案,那么请包括如何实现清晰的步骤。

I have no experience with ASP.NET so if this is involved in the solution then please include clear steps of how to implement.

原因我在web.config和不可以 PHP这样做,这是我想在站点内强制HTTPS上的所有资产。

The reason for me doing this with the web.config and not PHP is that I would like to force HTTPS on all assets within the site.

推荐答案

您需要的URL重写模块,preferably V2(我没有安装V1,所以不能保证它会在那里工作,但它应该)。

You need URL Rewrite module, preferably v2 (I have no v1 installed, so cannot guarantee that it will work there, but it should).

下面就是这样web.config中的一个例子 - 这将迫使HTTPS的所有资源(使用301永久重定向):

Here is an example of such web.config -- it will force HTTPS for ALL resources (using 301 Permanent Redirect):

<?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>

P.S。
它无关,与ASP.NET

P.S. It has nothing to do with ASP.NET

这篇关于如何强制HTTPS使用web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆