views:

677

answers:

2

Is there a definite DO and DONT when implementing seo urls? A lot of good practise seems fine for .html sites but breaks down on medium/large database sites.

AFAIK the url should be www.mysite.com/category/page-name-here

If I wish to make a content rich site and be default the category and page are database driven - does this prevent me from having pages such as www.mysite.com/about or www.mysite.com/home as the about and home pages could conflict.

Although the routing engine is flexible, is the above feasible and/or worthwhile?

-edit-

Just to elaborate on my question, is it possible to control the routing engine with a database?

It is good practice for the url to contain a meaningful description - eg stackoverflow.com/category/mvc and stackoverflow.com/questions/seo-urls-with-asp-net-mvc is good (as opposed to stackoverflow.com/category/9955 and stackoverflow.com/questions/734583)

As an expirment, I would like to take the control to another level, lets say that the two controllers above (category and questions), each showing dynamic data could be amended to be simply stackoverflow.com/mvc and stackoverflow.com/seo-urls-with-asp-net-mvc.

I would need to ensure that my database contained a table that tells me that the former is to be routed as a category and the latter as a questions - this could be achieved by a simple database lookup and would need to be implemented within Global.asax

My question is, can this be achieved and what would be the potential pitfalls.

+4  A: 

It's easily feasible if you add the harcoded routes above the generic ones:

// AboutController.Index()
routes.MapRoute( 
    "About",
    "about",
    new { controller = "About", action = "Index" });

// HomeController.Index()
routes.MapRoute( 
    "Home",
    "home",
    new { controller = "Home", action = "Index" });

// ArticleController.Index(string category, string pagename)
routes.MapRoute( 
    "Article",
    "{category}/{pagename}",
    new { controller = "Article", action = "Index" });

They could all use the same controller if you wanted, but it might be a bit easier if they used separate ones.

The only problem you would have with this is if you had a category called "about" or "home" but this is unlikely I would imagine.

It should also be noted that you don't have to use ASP.NET MVC to use the routing capability.

Garry Shutler
+4  A: 

To avoid the problems you mention with the static pages (about, home, etc.) you could take a few different aproaches:

  1. Put the dynamic category pages in a separate path (e.g. www.mysite.com/shop/category/page-name-here)
  2. Put the static pages in a separate path (e.g. www.mysite.com/pages/about). Now you can't have a category called "pages", but all other ones would work.
  3. Put the static routes above the dynamic routes. Not ideal since it could potentially hide category pages if you name your categories poorly, but even if you did #1 or #2, you would still want to do this as a just-in-case measure.

Other caveats/gotchas:

  1. You'll also need to ensure that your category names and page names are unique. On a large site this is not always trivial (or even practical) which is probably why you see URLs like the ones here on Stack Overflow where the question id is actually in the URL, and the "page name" part is just SEO sugar.

  2. You'll need to have a strategy for handling name changes. If a category name or page name is changed, you'll need to have something in place to redirect links to the old names to the new ones for maximum SEO goodness. You'll also want to make sure that the new name of a category/page isn't the same as the old name of another category/page, which adds a bit more complexity to the picture.

All that said, it is feasible, and it it certainly worthwhile in my opinion. Especially if you expect most of your traffic to come from search engines.

Eric Petroelje