次の方法で共有


Backwards compatibility and and preserving search engine ranking

Phew – that was a long title! This is a follow-up to a post that my colleague Josh wrote recently. I started typing a comment in response to one of the comments and it got a little bit cramped in the text box so I decided to post it here instead.

To summarise, Josh is looking into migrating the blog engine for his site to ASP.NET MVC and since he’s now running on IIS 7 wants to take advantage of extension-less URLs. His post talks about how to get routes working for both https://www.thejoyofcode.com/{PostLinkTitle}.aspx and https://www.thejoyofcode.com/{PostLinkTitle} using a route constraint to ensure that the latter doesn’t cause a match that includes the “.aspx” in the link title. Commenter valhallasw rightly points out that this approach will lead to splitting of the search engine ranking for pages as search engines will see these as two separate pages. An alternative is to issue a redirect from the old url to the new one, but how?

Well, one approach would be to do this at the IIS level, e.g. URL Rewrite. This is a valid approach and will perform the redirect nice and early in the request handling. But what if you don’t want to use it (or can’t for some reason)?

Rab commented that you could deal with this in the action method – the only change I’d suggest is to create a PermanentRedirectResult and return this as it simplifies testing (the good news is that this is coming in ASP.NET MVC 3, along with a RedirectToActionPermanent helper method!).

Another approach is to handle this directly in the routing. Phil Haack has a discussion of this approach that allows you to do something like routes.RedirectPermanently("home/{foo}.aspx", "~/home/{foo}")

All that’s left is to work out which approach works best for you :-)

 

Originally posted by Stuart Leeks on 3rd September 2010 here: https://blogs.msdn.com/b/stuartleeks/archive/2010/09/03/backwards-compatibility-and-and-preserving-search-engine-ranking.aspx