views:

609

answers:

3

I'm working a digg clone in ASP.NET MVC to help better teach myself ASP.NET MVC. I've been looking at how StackOverflow handles routing when passing in things like sorts and I guess I thought the whole point of using clean URLs is so you don't have things like ?sort=blah at the end of your URL for SEO.

Is there a recommended way of including many, possibly optional parameters into your URLs whilst still keeping them clean. I had a few ideas and I'd like to get some feedback.

Option 1:

Use wildcards (yuck)

Option 2:

Add the sorting to the beginning of the URL since it has the greatest coverage and ALWAYS applies when viewing stories. Exampke (using StackOverflow)

Instead of having ?sort=featured...

http://stackoverflow.com/featured/tagged/asp.net-mvc
http://stackoverflow.com/new/tagged/c#
http://stackoverflow.com/tagged/asp.net (some sort of default)

Anyway -- I can't seem to think of any other ways of doing this.

+1  A: 

You should go with a method that works best for you. Some things to consider:

  • maintainability: how will you maintain the link structure over the lifetime. How will someone else?
  • readability/debugging: How will you debug the links? Would natural language help you? (it helps me).
cbrulak
+1  A: 

Let's say you have a controller called StoryController which shows all your posts. You can make your routes look like this:

routes.MapRoute("FeatureTagged", "feature/tagged/{tag}", new { 
       controller = "Story", action = "ShowFeaturedByTag" });
routes.MapRoute("NewTagged", "new/tagged/{tag}", new { 
       controller = "Story", action = "ShowNewByTag" });

BTW, there's an ASP.NET MVC clone of digg already. It's called Kigg: http://www.codeplex.com/Kigg and it's being run on a site called DotNetShoutout

ajma
Yeah I looked through KiGG for answers and didn't really find one.
Chad Moran
+2  A: 

Hang on, stack overflow does use query string parameters for sort, e.g.:

http://stackoverflow.com/questions/518812?sort=oldest#sort-top

/featured is different. In this case you are controlling what records are returned, not just how their sorted.

URLs describe resources. Query string parameters described how the resources are presented. In general:

  • Fragments which describe the nature of the data returned should be part of the URL.
  • Fragments which describe how that data is presented should be query string parameters.

Having query string parameters will not hurt your SEO.

Craig Stuntz
Yeah I was just trying to give examples of it but I see what you're saying and if doesn't hurt SEO than I'll just use querystring params. Thanks!
Chad Moran
QSPs neither hurt nor help SEO, AFAIK. Throwing extra crap in the URL *can* help, though at the expense of correctness.
Craig Stuntz
Yeah, just with all of the hype around clean URLs and SEO I just figured it would be best to not use them. However it would look silly to have a HUGE url with nothing but /sort-votes/tag-blah/something-blah/. Thanks again.
Chad Moran