ASP.NET MVC - 301 重定向 - SEO 问题

发布于 2024-10-06 17:27:26 字数 440 浏览 5 评论 0原文

所以我有一个像这样的 ActionName:

[ActionName("Chicago-Bears")]
public ActionResult ChicagoBears() {
  return View();
}

Google 将此索引为: http://www.example.com/Teams /ChicagoBears

我无法使用 IIS6,并且自己无法访问 IIS。

当然,现在它里面有一个连字符。因此,如果有人点击该链接,Google 将显示 404。

在这种情况下如何设置 301 重定向?我无法创建另一个名为 ChicagoBears() 的方法,所以...

谢谢大家。

So I have an ActionName like so:

[ActionName("Chicago-Bears")]
public ActionResult ChicagoBears() {
  return View();
}

Google has this indexed as: http://www.example.com/Teams/ChicagoBears

I'm stuck using IIS6 and have no access to IIS myself.

Of course now, it has a hyphen in it. So, Google will show a 404 if someone clicks on that link.

How do I setup a 301 redirect in this instance? I can't create another method called ChicagoBears(), so...

Thanks guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南薇 2024-10-13 17:27:26

为 Teams/ChicagoBears 创建一条指向提供永久重定向的操作的路线。

在 Global.asax 中...

routes.MapRoute("ChicagoBearsRedirect",
    "Teams/ChicagoBears",
    new { controller = "Teams", action = "RedirectChicagoBears" }
);

在 TeamsController 中...

public ActionResult RedirectChicagoBears()
{
    return RedirectToActionPermanent("Chicago-Bears");
}

Create a route for Teams/ChicagoBears that points to an action that gives a permanent redirect.

In Global.asax...

routes.MapRoute("ChicagoBearsRedirect",
    "Teams/ChicagoBears",
    new { controller = "Teams", action = "RedirectChicagoBears" }
);

In TeamsController...

public ActionResult RedirectChicagoBears()
{
    return RedirectToActionPermanent("Chicago-Bears");
}
红颜悴 2024-10-13 17:27:26

URL 重写模块是您的朋友。学习它,生活它,热爱它...

http ://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

当我从 DasBlog 迁移到 WordPress 时,我广泛使用了它。我所有的旧博客 URL 都使用 301 重定向到新的 URL。强烈推荐。

更新:IIS6 有 URL 重写器。快速谷歌搜索出现:

(通过 http://forums.iis.net/t/1160436.aspx。)

The URL Re-Write Module is your friend. Learn it, live it, love it...

http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

I used it extensively when I migrated from DasBlog to WordPress. All my old blog URLs are re-directed using 301's to the new ones. Highly recommended.

UPDATE: There are URL re-writers for IIS6. A quick google search turned up:

(Found via http://forums.iis.net/t/1160436.aspx.)

撞了怀 2024-10-13 17:27:26

更新:我引用的这个博客似乎不再可用,因此我更新了链接以引用互联网存档版本。

查看此博客文章以获得出色的解决方案*:https://web.archive.org/web/20160528185929/http://www.eworldui.net/blog/post/2008/04/ 25/ASPNET-MVC-Legacy-Url-Routing.aspx

本质上他所做的是创建一个可用于多个路由的可重用类,并且它们只是向指定的 Action 方法发出永久重定向。

**注意:这不是我的博客,而是我偶然发现的一个。*

UPDATE: This blog I referenced seems to no longer be available so I updated the link to reference the internet archive version.

Check out this blog post for a great solution*: https://web.archive.org/web/20160528185929/http://www.eworldui.net/blog/post/2008/04/25/ASPNET-MVC-Legacy-Url-Routing.aspx

Essentially what he is doing is creating a reusable class that can be used for multiple routes, and they just issue a permanent redirect to the specified Action method.

**Note: This is not my blog, but one that I simply came across.*

≈。彩虹 2024-10-13 17:27:26

在这个聚会上有点晚了,但我写了 关于旧路由永久重定向的博客文章,允许此操作 -

routes.MapLegacyRoute(
    null, 
    "Teams/ChicagoBears", 
    new { controller = "Teams", action = "ChicagoBears", area="" }
);

要重定向到的 Location 是使用 Url.Action 使用路由值生成的,因此只要 RouteTable 中有与路由值匹配的路由,301 重定向就会按预期工作。在您的示例中,当 URL 模式与 "Teams/ChicagoBears" 匹配时,生成的 URL 应为 http://www.example.com/Teams/Chicago-Bears

我不会在这里重复代码,因为博客上有很多代码

Little late to the party on this one, but I wrote a blog post about permanent redirects for legacy routes that allows this -

routes.MapLegacyRoute(
    null, 
    "Teams/ChicagoBears", 
    new { controller = "Teams", action = "ChicagoBears", area="" }
);

The Location to redirect to is generated using the route values using Url.Action, so as long as you have a route in the RouteTable that matches the route values, the 301 redirect will work as intended. In your example, the generated URL should be http://www.example.com/Teams/Chicago-Bears when the URL pattern matches "Teams/ChicagoBears".

I won't repeat the code here as there's quite a bit and it's on the blog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文