Thursday, January 8, 2009

Sometimes you just need to look at the source code

I have been playing around with Dot Net Nuke recently, trying to figure out if I want to move to this as the main core backend for future websites and web applications I build.

One thing I have never liked about DNN is the way it creates urls. This is a link to the Blogs section of the DotNetNuke website and a typical example of what a DNN url looks like. http://www.dotnetnuke.com/tabid/825/default.aspx - with all pages having default.aspx at the end and actually being identified by the tabid number. This is just not a very friendly url and this is one of the main reasons I have avoided using DNN in the past.

With the latest round of research I have been looking for a way to get DNN to use a more friendly url structure such as http://www.dotnetnuke.com/blog.aspx etc...

I was looking at external addon modules to do this such as the cool looking Url Master Module from iFinity a company owned and run by Bruce Chapman from Sunshine Coast, Queensland, Australia http://www.ifinity.com.au/Products/Url_Master_DNN_SEO_Urls/. However, hesitate to commit myself to buying a $95 dollar add-on for every site I build. This kind of expense can really cut into your profit margin.

So today I took a good look at the source for the Friendly Url provider that comes with DNN and came across this setting: urlformat="HumanFriendly" which does exactly what I wanted.

To use this, just open your web.config and locate this tag:

<friendlyurl defaultprovider="DNNFriendlyUrl">
<providers>
<clear>
<add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includepagename="true" regexmatch="[^a-zA-Z0-9 _-]">
</add>
</clear>

Change it to :

<friendlyurl defaultprovider="DNNFriendlyUrl">
<providers>
<clear>
<add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includepagename="true" regexmatch="[^a-zA-Z0-9 _-]" urlformat="HumanFriendly">
</add>
</clear>

Save it and refresh your DNN application. Then you will see no tabid is in your urls.
Thanks to this post for helping me figure out the details of how to do this: http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/111/threadid/203804/scope/posts/Default.aspx

What I wanted was right there all along. However, I would not have realized this was built in if I hadn't taken a good look at the source code for the application and seen a switch that was turned off by default to use
Human Friendly urls.

The moral here is that
sometimes you just need to look at the source code.

1 comment:

Bruce said...

Hi Keith

Thanks for mentioning my add-ons. Just to give you a bit more information : the Url Master module licensing costs reduce as the number of sites goes up : you can get 5 licence packs as well as a host licence if you run many portals off a single DNN install.

You also seem to not have found the free version I distribute : called the 'iFinity Friendly Url Provider' This provides a mid-level point between the base 'HumanFriendly' option and the Url Master software. It adds features such as preserving the human friendly urls when using additional modules. The standard DNN provider stops producing Human Friendly Urls with add-on modules like the core blogs and forums. The iFinity Friendly Url Provider provides built-in 301 redirects to maintain a single, canonical Url for your DNN pages. You can read more here : iFinity Friendly Url Provider for DNN

-Bruce