【问题标题】:301 redirect from one website to another using asp.net web.config file301 使用 asp.net web.config 文件从一个网站重定向到另一个网站
【发布时间】:2014-08-25 07:19:46
【问题描述】:

我的旧网站有一个 HTML 页面,需要 301 重定向到新网站的 aspx 页面,这两个网站都是在 asp.net 平台上构建的。请建议我如何配置我的 web.config 文件来完成这项任务。 目前我正在使用 Meta Refresh 来执行此操作,但这可能是 200 而不是 301。

任何帮助将不胜感激,谢谢。

我在旧网站的 web.config 文件中使用了以下代码,但效果不佳

<configuration>
  <location path="http://example.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://newwebsite.com/test.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

【问题讨论】:

    标签: asp.net redirect seo


    【解决方案1】:

    在你的 web.config 文件中创建规则

    <system.webServer>
        <rewrite>
          <rules>
             <rule name="URL1" stopProcessing="true">
              <match url="^abc.html" ignoreCase="true" />
              <action type="Redirect" url="Your current page path" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
     </system.webServer>
    

    【讨论】:

    • +1 在不添加或安装任何特殊模块或功能的情况下是否可以使用?
    • 您的代码适用于普通 url,但我无法在 url 中指定任何查询字符串,因为 IDE 在编译时出错。例如我想重定向到 - test.com/?area=90&startDay=31/12/2014" redirectType="Permanent" />
    • 标签之间再添加一个标签 条件>
    • @Nathaniel :是的,如果未安装,您需要在 iis 上安装重定向工具
    • 我收到一个错误。元素“system.webServer”的子元素“rewrite”无效。
    【解决方案2】:
    <configuration>
        <system.webServer>
            <httpRedirect enabled="true" destination="http://uri" httpResponseStatus="Permanent" />
        </system.webServer>
    </configuration>
    

    抱歉,我没有针对单页的 web.config 解决方案。您需要将其放置在靠近顶部的标记页面中:

    <% RedirectPermanent("http://url", true) %>
    

    如果它对您不起作用,请在此处发布您的标记,我会为您更新。

    【讨论】:

    • 我应该在哪里指定需要重定向的旧网址
    • 您是否尝试仅重定向单个 uri?以上重定向域的所有请求。如果您的目的地需要知道来源,您可以打开 childOnly。否则,如果您只想重定向单个 Uri,我们需要不同的解决方案。
    • 是的,我想重定向单个 uri
    • 我可以看到目标网址,但源网址在哪里或要重定向哪个网址??
    • 您将代码放在要重定向的页面(可能是 .aspx)中。此解决方案不是配置解决方案。
    猜你喜欢
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    相关资源
    最近更新 更多