Configuring DotNetNuke to Produce a Human Friendly URL

One of the big complaints that I have seen over the years with DotNetNuke has been the horrible URL’s that get produced by the framework.  This is a problem that is part of most dynamically created content on the web, not only DotNetNuke.

For the successful Content Management Systems, they have come up with ways to make these ugly URL’s more human friendly.  DNN did this back in about version 3.0 with the introduction of Friendly URL’s.  This allowed us to get rid of the dreaded querystring for SEO purposes.  So we went from URL’s that looked like http://domain.com/Default.aspx?tabid=39 to http://domain.com/Home/tabid/36/Default.aspx.

This was great for getting better rankings with the pages in the search engines but doesn’t give us that URL that is easy to remember in human terms.  This is the default setup that has made it’s way into the DotNetNuke eco-system, and has given us this common complaint about DotNetNuke sites in general.

There is a solution to this that anyone who is looking to make their site distinctive and remove that stigma about it being a DNN site can use.  It is available within the core framework itself we just need to make some changes to the configuration of the web application.

So lets look at the default configuration in the web.config file for the Friendly URL provider:

   1: <friendlyUrl defaultProvider="DNNFriendlyUrl">
   2:   <providers>
   3:     <clear />
   4:     <add name="DNNFriendlyUrl" 
   5:         type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" 
   6:         includePageName="true" 
   7:         regexMatch="[^a-zA-Z0-9 _-]" />
   8:   </providers>
   9: </friendlyUrl>

As you can see it only has a couple of options defined by default in the config file when you first install DNN which are the following:

  1. includePageName: this is set to true by default and determines if we have the name of the page included in our URL when we are in searchfriendly mode of the provider.
  2. regexMatch: I'm not a regex expert by any means.  But the default match allows the inclusion of all upper and lower characters as well as ll numbers, spaces, underscores and dashes.  If I’m wrong someone let me know in the comments would you.

This is what gives us those ugly URL’s everyone complains about. 

Now when we venture into the Core Framework code for the FriendlyUrl Provider, we have a few more options that aren’t shown in the web.config and can really give us some nicer URL’s to work with on our DNN site.

FriendlyURL Provider Options

  1. includePageName: this was explained above.
  2. regexMatch: this was explained above
  3. fileExtension: by default the file extension on DNN is .aspx. I played around with this option and also looked at the code and although it is defined and being pulled into the provider in the code. I don’t see where this is actually doing anything in provider.
  4. urlFormat: this is the real treasure in the provider we have two URL formats that we can use here the default of searchfriendly or humanfriendly. If we do not include it in the web.config then by default it is searchfriendly but if we add this and change it to humanfriendly then we have much nicer URL’s to work within the framework.

So lets change it in our web.config file to be humanfriendly:

   1: <friendlyUrl defaultProvider="DNNFriendlyUrl">
   2:   <providers>
   3:     <clear />
   4:     <add name="DNNFriendlyUrl" 
   5:         type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" 
   6:         includePageName="false" 
   7:         regexMatch="[^a-zA-Z0-9 _-]" 
   8:         fileExtension=".aspx" 
   9:         urlFormat="humanfriendly" />
  10:   </providers>
  11: </friendlyUrl>

Once we do this and save our web.config file. We can go refresh our site, and now should have URLs that look like the following: http://domain.com/home.aspx or http://domain.com/admin.aspx.  It also makes it easier for allowing direct logins without placing a link on the page for logging in because in this format our login page becomes http://domain.com/login.aspx.

I hope that people find this information useful although what we have in DNN is just a basic URL provider there are other providers out there in the DNN community.  When I have time I will try to add some of them to this post or provider another post with a list of them out there.

Technorati Tags: ,,

Posted on 5/16/2009 9:59:31 AM by omacdon

Permalink | Comments (5) | Post RSSRSS comment feed |

Categories: ASP.NET | DotNetNuke | Programming | Software

Tags: , , ,

Comments

May 19. 2009 03:12

almny

thanks for this post
but i want to ask this way it's safety i meaning about securty no problem to use friendlyUrl

almny U.A.E.

May 19. 2009 08:02

omacdon

There's no security issue with using this provider.  It's merely cleaning up the URL to make it nicer to look at and easier to remember.

omacdon United States

May 25. 2009 00:13

Bruce Chapman

The regexMatch field does show you what the match will be.  The regex pattern matches any upper/lower case letters, digits, as well as a space or an underscore or hyphen.

The regexMatch field is used in the generation of Friendly urls. If you have a Url in your site which doesn't match this regex pattern, it will show up in the 'unfriendly' manner - the offending key/value pair will be removed from the path and added to the querystring.

Just as a note, the human friendly portion of the urls reverts back to the /tabid/xx path if you have a module on the page which adds extra querystring/path information.  So adding a blog will get you /tabid/xx/blog/entryid/xx/blog-post-name instead of blog/blog-post-name.

You are correct in that the core friendly url provider allows specification of the page extension, but doesn't actually do anything.

Bruce Chapman Australia

June 1. 2009 05:24

Thomas Richards

I was just thinking about Configuring DotNetNuke to Produce a Human Friendly URL and you've really helped out. Thanks!

Thomas Richards United States

August 21. 2009 15:36

trackback

Learn MS .NET | Configuring DotNetNuke to Produce a Human Friendly URL

One of the big complaints that I have seen over the years with DotNetNuke has been the horrible URL’s that get produced by the framework.  This is a problem that is part of most dynamically creat ...

Bonderblog

Comments are closed