Derik Whittaker

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Using the MVC Route engine to preserve URL Routes for SEO

Today I was making some changes to the DimeCasts.Net site and I realized that I did not like the URL's that I was currently using as I did not feel they accuracy reflected the intent of the route.  However, because Google has already linked many of the episodes on the site, I did not want to break those links.  At the same time I did not want to leave obsolete code laying around in my controllers. 

So what was I to do?  Simple, use the Routing engine to my advantage.

Below you find both the old URL and the new URL, notice the subtle change

Old: ../Casts/CastItemsByLevel/Advanced
New: ../Casts/CastsByLevel/Advanced

Basically all you need to do is the following

  1. Rename your old controller action to your new controller action name.
    Hint: If you are using a tool like ReSharper or CodeRush, they may be helpful here.
  2. Duplicate (copy/paste) your old route (assuming you have created a new route).
    1. Change the name of the route.  I added a _obsolete
    2. Leave the URL parameter the same
    3. Modify the parameter defaults to reflect your new controller action
      new { controller = "Casts", action = "NewActionNameHere" }
  3. Modify your new route to be the correct route for the new URL you desire
  4. Update your view name if you desire, or you will have to specify that in your RenderView call
  5. Test/Ensure that the old route goes to your new controller action
  6. Test/Ensure that your new route goes to your new controller action
  7. Sit back and be satisfied that you have not broken any external links

Here are my routes, both old and new:

// old route
routes.MapRoute(
    "CastsByLevelName_obsolete",                                         // Route name
    "Casts/CastItemsByLevel/{levelName}",               // URL with parameters
    new { controller = "Casts", action = "CastsByLevel" } // Parameter defaults
);

// new route
routes.MapRoute(
    "CastsByLevelName",                                         // Route name
    "Casts/CastsByLevel/{levelName}",               // URL with parameters
    new { controller = "Casts", action = "CastsByLevel" } // Parameter defaults
);

Hope this helps someone.

Till next time,

[----- Remember to check out DimeCasts.Net -----]


Posted 06-03-2008 7:29 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Dew Drop – June 4, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop – June 4, 2008 | Alvin Ashcraft's Morning Dew
on 06-04-2008 8:40 AM

Pingback from  Dew Drop – June 4, 2008 | Alvin Ashcraft's Morning Dew

Christopher Steen wrote Link Listing - June 4, 2008
on 06-05-2008 6:39 AM

Link Listing - June 4, 2008

Christopher Steen wrote Link Listing - June 4, 2008
on 06-05-2008 6:39 AM

MSBuild DevSource Article: Automation with MSBuild [Via: Steve ] WPF The Missing .NET #4: Cue Banner...

Mr d wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 02-27-2009 10:33 AM

Sit back and be satisfied that you will be penalized by Google for duplicate content because you didn't set up your 301 redirections.

"Derik is a .Net Developer/Architect specializing in WINFORMS"

Derik Whittaker wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 02-27-2009 10:37 AM

@Mr D

Been like this for months, and no issues with Google.

vanessa hudgens sex tape wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 06-11-2009 1:32 PM

Here best for you Free vanessa hudgens sex tape

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 3:30 AM

What is it,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 7:06 AM

Best Wishes,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 10:41 AM

Your Site Is Great!,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 2:18 PM

Your Site Is Great!,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 5:45 PM

Help me to find the,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-29-2009 9:04 PM

Real,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-30-2009 12:25 AM

Great,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-30-2009 3:46 AM

Hi,

name wrote re: Using the MVC Route engine to preserve URL Routes for SEO
on 07-30-2009 7:11 AM

best for you,

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)

CodeBetter.Com