【问题标题】:How can i configure in web.config a 301 permanent redirect?如何在 web.config 中配置 301 永久重定向?
【发布时间】:2011-11-13 14:39:05
【问题描述】:

我很想使用 web.config 进行从旧域到另一个域的 301 重定向。 我怎么能这样做?

在您的回答中,请记住 IIS 是 v7 和

我不想使用任何第三方 dll,例如 urlrewriteing.net 等,也不想使用 ASP.NET 代码或配置 IIS。

我确信这可以做到,但是怎么做呢?

更新:我尝试了 Parvesh 的答案,但我觉得它不是“官方”支持的,或者我正在做其他非常错误的事情。

【问题讨论】:

    标签: asp.net iis-7 redirect web-config http-status-code-301


    【解决方案1】:

    你需要在 IIS 下安装 URL 重写模块,然后你可以在 web.config 中使用它。

    <configuration>
    <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"
               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    </system.webServer>
    </configuration>
    

    【讨论】:

    • 对不起,“URL 重写模块”到底是什么意思? (这很好,但我觉得“重写”规则不受官方支持)
    • url 重写模块是微软官方支持的 IIS 7 插件。您可以使用 Web 平台安装程序或从他们的网站安装它。此处信息:iis.net/download/urlrewrite
    • 其实我不明白的是VS 2010中重写的这些卷发
    • 智能可能不适用于 URL 重写器模块
    • 我在使用仅适用于 www 的 Google AdSense 时遇到了问题。现在一切都很完美。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2012-05-31
    相关资源
    最近更新 更多