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:
- 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.
- 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
- includePageName: this was explained above.
- regexMatch: this was explained above
- 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.
- 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.