【问题标题】:301 redirects after domain name change域名更改后的301重定向
【发布时间】:2013-06-29 20:12:48
【问题描述】:

我在 IIS 上运行一个小型 ASP.NET4 网站。我最近将域名从“olddomain.com”更改为“newdomain.com”。更改是通过 Plesk 进行的。进行更改后,我在 plesk 中添加了“olddomain.com”作为域别名,这样流量仍会路由到旧域上的网站。

到目前为止还不错。该网站同时解析旧 URL 和新 URL。

但是,现在我想在任何地方设置 301 重定向,以便将对 olddomain.com 的任何请求转发到 newdomain.com。网站页面没有任何变化 - 只是简单的域名更改。

我已将此添加到 web.config 文件中:

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

但是好像没有什么影响;当我在浏览器中加载 olddomain.com 时,它只会加载网站而不重定向到 newdomain.com。

谁能建议我在这里做错了什么以及如何让 301 工作?

谢谢

【问题讨论】:

  • 你能不能只添加一个简单的 HTTP 页面并带有 meta 重定向到新域?

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


【解决方案1】:

这行得通:

<rule name="redirectDomain" stopProcessing="true">
    <match url="(.*)" />
    <action type="Redirect" url="http://www.newdomain.com/{R:1}" redirectType="Permanent" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^(www.)?olddomain\.com$" />
    </conditions>
</rule>

【讨论】:

    【解决方案2】:

    您也可以从 IIS 设置 301 永久重定向。

    如果在旧服务器上启用了 http 重定向,那么您必须将新的 web 配置与内容一起放置 -

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <httpRedirect enabled="true" destination="http://mynewsite.com/" httpResponseStatus="Permanent" />
        </system.webServer>
    </configuration>
    

    如果有帮助,请告诉我。

    【讨论】:

    • 谢谢,但是该站点在同一台服务器上,所以我认为这种方法行不通。网站文件一直在原处,只是在 Plesk 中更改了域名。
    猜你喜欢
    • 2019-04-29
    • 2015-04-26
    • 1970-01-01
    • 2015-09-27
    • 2015-12-04
    • 1970-01-01
    • 2011-05-10
    • 2012-08-12
    相关资源
    最近更新 更多