【问题标题】:Create 301 redirect in windows server在 windows server 中创建 301 重定向
【发布时间】:2013-02-10 08:33:48
【问题描述】:

我使用 IIS 管理器中的 URL 重写 部分为我的网站创建一个 redirect 301,并将 搜索引擎 和用户从 DomainName.com 重定向到 www.DomainName.com。在 IIS 中为此目的创建规则后,它会在 web.config 文件中生成以下代码:

<rewrite>
    <rules>
        <rule name="redirect 301" stopProcessing="true">
            <match url="^DomainName\.com.*" />
            <action type="Redirect" url="www.{R:0}" />
        </rule>
    </rules>
</rewrite>

但它对我不起作用。

我的代码中是否有任何错误,或者我必须使用其他方法来执行此操作?

【问题讨论】:

    标签: iis-7 asp.net-mvc-4 web-config http-redirect


    【解决方案1】:

    我在Scott Guthrie post 中找到了答案:场景 4:规范主机名, 为此,我必须创建 canonical domain name 规则并编写我的主 url 以将其他形式的 url 重定向到该规则。 web.config 文件中的代码是这样的:

    <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.domainName\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.domainName.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多