【问题标题】:I need to redirect both http and www version of my website to https version (web.config)我需要将我的网站的 http 和 www 版本都重定向到 https 版本(web.config)
【发布时间】:2015-05-01 22:20:21
【问题描述】:

您好,请帮我解决我网站的重定向问题。

我想将我的 domain.com、www.domain.com 重定向到 https://www。域.com。

目前我有以下代码可以重定向。

<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="^(\w*/)?index\.php" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain\.com$" />
</conditions>
<action type="Redirect" url="https://www. domain.com/{R:1}" />
</rule>

<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" />
</conditions>
<action type="Redirect" url="https://www. domain.com/{R:1}" />
</rule>

现在,我的 domain.com 正在重定向到 https://www。 domain.com 但是, www 。 domain.com 不会重定向到 https 版本。我尝试了一些搜索代码,但我收到了重定向循环错误。请分享您的建议以解决此问题。

【问题讨论】:

标签: redirect web-config url-redirection http-redirect


【解决方案1】:

以下规则将处理 www 和非 www 请求的 http 到 https,并且所有请求的最终 url 将相同 https://www.domain.com

网络配置副本:

<rewrite>
     <rewriteMaps>
            <rewriteMap name="root">
                <add key="/root/" value="/" />
            </rewriteMap>
        </rewriteMaps>
        <rules>
            <rule name="To HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="SeeOther" />
            </rule>
        </rules>
    </rewrite>

您可以通过 GUI 和 URL rewrite module: 进行此操作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2019-10-05
    • 1970-01-01
    • 2011-06-27
    相关资源
    最近更新 更多