【问题标题】:Redirect URLs ASP.net core, Google Searches重定向 URL ASP.net 核心,Google 搜索
【发布时间】:2021-03-26 19:39:34
【问题描述】:

我的网站以前是用 ASP.net 实现的。我使用 ASP.net 核心重新实现了它。它由不同的托管服务托管,但域名相同。页面的 URL 已更改。例如:

旧网址:https://www.roberttayloronline.com/Trips/2019PineRiverTrail/2019PineRiverTrail.aspx

新网址:https://roberttayloronline.com/recreation/trips/2019-pine-river-trail

当我使用 Google 搜索“Pine River Trail, Weminuche Wilderness”时,Google 会显示旧的 aspx 网址。我已经使用 Google Search Console 提交了一个新的站点地图。我知道如何从 Google 中删除旧网址,但我希望 Google 重定向它,而不是删除它。

我不知道如何指示 Google 搜索进行此更改。这可能吗?

我还认为我可以通过在 startup.cs 文件的 Configure 方法中包含类似这样的代码来重定向 URL 到我的网站来解决这个问题:

var rewriteOptions = new RewriteOptions().AddRedirect(
    @"(?i)(\/Trips\/2019PineRiverTrail\/2019PineRiverTrail\.aspx)",
    "https://roberttayloronline.com/recreation/trips/2019-pine-river-trail",
    (int)HttpStatusCode.MovedPermanently);
applicationBuilder.UseRewriter(rewriteOptions);

但我没有让它发挥作用。旧网址出现 404 错误。

有人能指出我正确的方向吗? 谢谢。

【问题讨论】:

    标签: asp.net asp.net-core redirect


    【解决方案1】:

    我找不到直接指示 Google 重定向旧网址的方法。

    将这样的代码放在我网站的 web.config 文件中将重定向 URL:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <rewrite>
            <rules>
              <rule name="rule-01" stopProcessing="true">
                <match url="Trips\/2019PineRiverTrail\/2019PineRiverTrail\.aspx" />
                <action type="Redirect" url="https://roberttayloronline.com/recreation/trips/2019-pine-river-trail" redirectType="Permanent" />
              </rule>
            </rules>
          </rewrite>
        </system.webServer>
      </location>
    </configuration>
    

    更多信息可以在这里看到:https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多