Monday, May 07, 2012

Human readable URLs, and Routing in WebShell

It’s been on the to-do list of WebShell improvements for a long time. Turning the URLs (addresses) in our content management system (CMS) into something a bit better for humans.

I will use a client site for an example, the address of the “about us” page for Boyd HQ used to be “http://www.boydhq.co.nz/default.aspx?Page=4099” but with the upgrade it becomes “http://www.boydhq.co.nz/c/About-Us” (note: the old address still works to so any bookmarks search results and links are still good).

Why did we do this?
Two reasons
1) It just looks nicer
2) The addresses are much more memorable and easier to direct people to

Why now?
While there have been ways to do this in the past, with things like URL rewriting or generating a file for each page, they were mucky and not that robust. The routing technology introduced in previous versions and improved in version 4 of the .net framework has changed things.

How it works for anyone interested
Neither “http://www.boydhq.co.nz/c/About-Us” or “http://www.boydhq.co.nz/c” actually exist as real files or directories, "/c" (c for content) exists only virtually as a rout to "/default.aspx" (the same page used in the old system) the rout passes with it the page variable, (in this case "About-Us")  WebShell uses this variable (just like it can use "Page=4099") to pull the correct content from its SQL server database and display it within the page template. Routing can be used for much more complex URLs with many more variables and we look forward to using it more in the future to produce better and more human friendly URLs in other projects.
And in case you were wondering where the page address "About-Us" comes from WebShell first tries to use the navigation title of a page (in this case About Us), then the long title then several combinations of the 2 titles with parent pages until it finds an address that is unique within the website so even if you give 5 pages the same name in the navigation they will be given different addresses by WebShell. In most cases there will only be one and your page is just named the same as it is in the navigation with spaces replaced with a dash.