Enabling Friendly URL Rewriting

Overview

DNN Evoq uses a built-in Friendly URL Provider to rewrite complex URLs in a simpler, more readable way. There are three URL Rewriting modes included in DNN (Advanced, Humanfriendly, and Searchfriendly), with more available via third-party providers. These modes control what and how much of a URL is rewritten (for example, whether to remove “.aspx” from file names). These modes can be changed in web.config by changing the urlFormat value.

See the Information section below for descriptions of the different URL Rewriting modes, or skip to the Solution section to learn how to change this setting for your site.

 

Information

Every page needs a unique identifier. Internally, DNN uses a unique “tabid” as its page identifier (the use of "tab" rather than "page" is for historical reasons related to third-party modules). When a URL is requested, DNN uses a Friendly URL Provider to translate the human-readable URL into the unique tabid for the requested page. The Friendly URL Provider contains a set of rules as to how these URLs are translated into precise file locations.

Because URL rewriting is done via a provider, third-party URL providers can be added if extra functionality is needed. DNN’s built-in Friendly URL provider can operate in three modes, described below:

 

No Friendly URL Rewriting

When no urlFormat is specified in web.config, pages are loaded based on their unique identifier and have the form: 

www.mysite.com/default.aspx?tabid=99

Unique identifiers are displayed and query strings are not hidden. We'll use this URL to demonstrate how the three modes below would render this address.

 

Advanced URL Rewriting

Advanced URLs were added in DNN 7.1 and greatly increase the functionality of URLs. This includes simplified URLs for pages, the ability to redirect to the Canonical URL, using different URLs for different languages, and more. 

Advanced URL rewriting removes tabids and file extensions where possible, and writes query strings a part of the virtual directory structure.  Advanced rewriting renders URLs in the form:

www.mysite.com/home

All new DNN installs from 7.1 onwards use the advanced mode by default.

 

Humanfriendly URL Rewriting

Humanfriendly URLs use the name of the DNN page as a "virtual" URL (if unique and valid). In this case, the page could look like:

www.mysite.com/home.aspx

Humanfriendly URLs use simple URLs for page names, but still use tabids in more complicated URLs

 

Searchfriendly URL Rewriting

Searchfriendly URLs use a regex pattern in the siteurls.config file to match the URL against a pattern that includes the page name and the tabid. Searchfriendly URL rewriting might render our URL in the form:

www.mysite.com/Home/tabid/99/default.aspx

The search friendly option was the first URL rewriting option available in an earlier version of DNN and is retained for backward compatibility.

 

Solution

Enabling/Configuring Friendly URLs

‘Advanced’ mode is available on DNN versions 7.1+. Earlier versions of DNN (from DNN 4.6 to DNN 7.0) can only use 'searchfriendly' and 'humanfriendly' modes of Friendly URLs.

If you're running a version prior to 4.8 you must login as a host (superuser) user, and go to Host->Host Settings and ensure that "Enable friendly URLs" is checked.

 

  1. Access the root DNN folder and find the web.config file (/Websitefolder/web.config)
  2. To choose between the three modes, change the urlFormat attribute of the DNNFriendlyUrl provider declaration in the web.config file:

    <add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includePageName="true" regexMatch="a-zA-Z0-9 _-" urlFormat="advanced"/>

    The options for urlFormat are:
  • "advanced"
  • "humanfriendly"
  • "searchfriendly"

 

Testing

You should be able to test that friendly URL is working correctly after setting the urlFormat from humanfriendly to advanced by:

  1. Try to access any page on the website.
  2. The URL format in the Address bar should be converted from (website.com/mypage.aspx) to (website.com/mypage)

 

Comments

0 comments

Please sign in to leave a comment.