IIS 7.5 URL特定模式的重定向 [英] IIS 7.5 URL Redirect for specific patterns

查看:448
本文介绍了IIS 7.5 URL特定模式的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户输入domain.com时,它应该重定向到我的应用程序,即 https://www.domain.com 。目前它没有发生,它显示一个页面此连接不受信任。

When user enters domain.com it should redirect to my application which is https://www.domain.com. Currently it is not happening and it is showing a page "This Connection is Untrusted."

我在web.config中添加了以下重写标记:

I have following rewrite tag added in my web.config:

        <rewrite>
           <rules>
            <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
            </rule>
       </rules>
    </rewrite>

目前在我的IIS 7.5中,我添加了入站规则,我的设置如下:

Currently in my IIS 7.5 i have added Inbound Rule which i have settings as follows:


  1. 匹配网址

  1. In Match URL

请求的网址:匹配模式

使用:Reqular Expression

Using: Reqular Expression

模式:(。*)

忽略案例:已检查

条件

逻辑分组:全部匹配

输入:{HTTPS}

Input: {HTTPS}

类型:匹配模式

模式: ^ OFF $

Pattern: ^OFF$

跨越条件跟踪组:未选中

Track group across condition: unchecked

行动

行动类型:重定向

重定向网址:https:// {HTTP_HOST} / {R:1}

Redirect URL: https://{HTTP_HOST}/{R:1}

追加查询字符串:已选中

Append Query string: checked

重定向类型:请参阅其他(303)

Redirect Type: See Other (303)

如果可以对现有设置进行任何更改,请与我们联系。

Please let me know if any changes can be made to existing settings.

提前致谢。

推荐答案

你的回报te规则只是重定向到同一个域。因此,如果用户只输入 domain.com (默认为http),它将重定向到 https://domain.com 。如果您的SSL证书不包含 domain.com 但仅包含 www.domain.com ,则会导致浏览器提示关于错误证书的警告。虽然现在大多数证书颁发机构都使用带有和不带www的域颁发证书(但可能不是你的)。

Your rewrite rule is just redirecting to the same domain. So if a user enters just domain.com (defaulting to http) it will redirect to https://domain.com. If your SSL certificate does not contain domain.com but only www.domain.com it will cause the browser to prompt a warning about a wrong certificate. Though most certificate authorities nowadays issue certificates with both the domain with and without www (but maybe yours not).

如果你希望用户总是使用 https://www.domain.com (始终使用www)您应使用以下重写规则:

If you want the user to always use https://www.domain.com (always with www) you should use the following rewrite rule:

<rule name="Force HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" negate="true" pattern="^ON$" />
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.domain\.com$" />
    </conditions>
    <action type="Redirect" url="https://www.domain.com{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>

它将强制使用SSL并强制 www.domain.com 作为主机头。如果没有,它将向同一URL发出永久重定向(= beter)。

It will force SSL and will force www.domain.com as a host header. If not, it will issue a permanent redirect (= beter) to the same URL.

这篇关于IIS 7.5 URL特定模式的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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