Let’s say I had a fresh MVC site and I wanted to implement URLs in the following manner. What are some thoughts on the best way to do this from a routing perspective? I would be storing posts in a basic database table. I would want to keep it as simple as possible from a controller/action perspective.
/2011/ (all posts from 2011)
/2011/11/ (all posts from November 2011)
/2011/11/07 (all posts from November 7th 2011)
/2011/11/07/exact-post-title
/exact-post-title
/about
/archive
/tag/whatever-tag
There is sort of a problem with the /exact-post-title route. That is going to match pretty much anything you send it. You would have to put every other possible route in front of that one in order to fix that. You could also just prefix all of these routes with /blog or /articles to fix it:
Now it won’t conflict with the following:
Archive would be similar:
And finally the Tag route:
You might have to play around with the order of the routes, but in general you always want the most specific routes first.
If you had the following routes:
The first route matches /about so you are going to run into problems if they are in that order.