301 从 IIS 6 上的 web.config 重定向

Posted

技术标签:

【中文标题】301 从 IIS 6 上的 web.config 重定向【英文标题】:301 Redirect from web.config on IIS 6 【发布时间】:2013-02-06 19:28:58 【问题描述】:

我需要从 IIS 6 服务器(Windows 2003 Web 服务器)上的 web.config 进行 301 重定向。 我是 Apache 服务器的人,对 Windows Web 服务器一无所知。我只能通过 FTP 访问服务器。

我在另一个问题中找到了以下内容,但它似乎不起作用:

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

我需要将单独的页面从 mydomain1.com 重定向到 mydomain2.com。 前任。 mydomain1.com/somename 应该重定向到 mydomain.com/someothername 如何才能做到这一点?

---- 编辑 ---- 在 *** 上看到另一个线程后,我的配置现在看起来像这样:

<system.webServer>
    <rewrite>
        <rule name="rule1">
            <match url="default.aspx"/>
            <action type="Redirect" redirectType="Permanent" url="http://www.mydomain.com/somename/somename.aspx"/>
        </rule>
        <rule name="rule2">
            <match url="somename.aspx"/>
            <action type="Redirect" redirectType="Permanent" url="http://www.mydomain2.com/somename2/somename2.aspx"/>
        </rule>
    </rewrite>
</system.webserver><br>

--- 编辑 2 ---- 重定向根的代码:

【问题讨论】:

您需要安装iis.net/downloads/microsoft/url-rewrite 才能使其正常工作。是吗? 我会检查的。我需要联系托管支持。他们的支持也无法帮助我回答我的问题,所以我希望他们能回答这个问题。 好的,该站点现在移动到另一个安装了 IIS8 和 url-rewrite 的服务器。我再次尝试了上面的代码,但我得到的只是一个错误:“HTTP Error 500.19 - Internal Server Error The requested page cannot be used because the related configuration data for the page is invalid.” 看到这个错误,如果没有安装 URL Rewrite,你会得到这个错误。要测试,尝试删除整个重写段,应该可以正常工作,将其放入,它会倒下。 谢谢丹尼尔。我再次联系了支持人员并解释了情况。他们要求我再次上传 web.config 文件,以便他们查看。突然间它起作用了。 【参考方案1】:

据我调查,在 IIS6 上无法通过 web.config 进行重定向。

rewrite 和 httpRedirect 指令只能在 IIS7 相同或之后使用。

但你可以使用ISAP way with paid solution。

所以,我认为Response.Redirect("direct to"); 是最好的方法

【讨论】:

以上是关于301 从 IIS 6 上的 web.config 重定向的主要内容,如果未能解决你的问题,请参考以下文章