【问题标题】:URL Rewrite for New Domain Name新域名的 URL 重写
【发布时间】:2016-03-08 16:08:44
【问题描述】:

我正在尝试在 IIS 中创建 url 重写。我们已经在服务器上安装了 SSL 证书,并且需要所有连接都是 HTTPS。 HTTPS 重写规则似乎工作正常。

我们遇到的问题是整个组织的用户都有服务器名称的书签。因此,他们将收到有关服务器名称与证书不匹配的安全警告。示例:https://mywebserver/BI/Default.aspx

我需要重写域,以便将它们重定向到https://mywebserver.abcxyz.com/BI/Default.aspx

我创建的当前规则将重定向到 HTTPS。它还会将域从https://mywebserver/ 重写为https://mywebserver.abcxyz.com

我遇到的问题是,如果服务器名称后面有任何内容,它将不起作用。无效域示例:http://mywebserver.abcxyz.com/BI/Default.aspx

有什么建议吗?这是我目前在 web.config 中的内容。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1" enabled="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^mywebserver\.abcxyz\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://mywebserver.abcxyz.com/{R:1}" />
            </rule>
            <rule name="Redirect to HTTPS" enabled="true" 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>
</system.webServer>

【问题讨论】:

    标签: asp.net asp.net-mvc iis ssl url-rewriting


    【解决方案1】:

    尝试这样的事情并同时执行 HTTPS,这样您就不会有 2 个单独的重定向

    <rule name="CanonicalHostNameRule1" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="mywebserver.com" />
      </conditions>
      <action type="Redirect" url="https://mywebserver.abcxyz.com/{R:1}" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 2013-04-08
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      相关资源
      最近更新 更多