开发者

ASP.NET MVC - 301 Redirect - SEO issue

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.


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");
}


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:

  • http://www.isapirewrite.com/
  • http://urlrewriter.net/

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


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.*


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜