【问题标题】:ASP.NET URL rewriting and tag the old URL to 301ASP.NET URL 重写并将旧 URL 标记为 301
【发布时间】:2015-03-25 08:45:56
【问题描述】:

您好,我正在尝试将我的网址:www.mydomain.com/hw/Index.aspx 重写为 www.mydomain.com/hello-world/index.aspx。这是我在 web.config 中的代码:

    <rule name="Redirect to WWW" stopProcessing="true">
      <match url="^hello-world/index.aspx" />
      <action type="rewrite" url="hw/Index.aspx" />
    </rule> 

这个问题是我有两个 URL 和同一个页面。

  1. www.mydomain.com/hw/Index.aspx
  2. www.mydomain.com/hello-world/index.aspx

我想做的是当用户浏览 www.mydomain.com/hw/Index.aspx 它将被标记为 301 并将重定向到 www.mydomain.com/hello-world/index.aspx

请帮帮我。

提前致谢。

【问题讨论】:

    标签: c# asp.net redirect


    【解决方案1】:

    rewrite 本质上使 IIS 为用户提供相同的页面,它在内部重写 URL 并将其传递给您的应用程序。

    另一方面,rewrite 实际上会向客户端发送一个响应,表明所请求的资源已移动(即 301)

    要解决此问题,请将操作类型从 rewrite 更改为 redirect

    <rule name="Redirect to WWW" stopProcessing="true">
      <match url="^hello-world/index.aspx" />
      <action type="redirect" url="hw/Index.aspx" />
    </rule> 
    

    【讨论】:

    • 嗨,DavidG,问题在于它总是会将我的 URL 重定向到 www.mydomain.com/hw/Index.aspx 而不是 www.mydomain。 com/hello-world/index.aspx。我需要的是 www.mydomain.com/hello-world/index.aspx。请指教。
    • 你的规则刚刚回到前面,切换匹配和操作url的值。
    猜你喜欢
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 2014-11-13
    • 2021-12-27
    • 1970-01-01
    • 2010-11-09
    相关资源
    最近更新 更多