Changing the URL Extension for a DNN Site
The introduction of Advanced URLs in DNN 7.1 meant that, by default, new DNN sites run without any extensions on the URLs. The URLs for DNN pages are the domain name and the path to the DNN page, such as example.com/about-us in contrast to earlier DNN versions which always appended an extension of .aspx onto the end of the URL.
However, some site owners wish to associate an entirely different URL extensions to their DNN sites. The reasons for doing this might be:
- Preserving an existing URL scheme for sites which are migrating to DNN from a different framework or technology
- Obfuscating the technology the site is using
- Meeting a pre-determined mandate on URL extensions
While not a common request, it is entirely possible to change the URL Extension at a site level for DNN pages. The extension can be changed to any valid value, from .htm, to .php, to .asp, to .mydnnpages. As long as the web server knows that the request belongs to the DNN app, it can be setup to work.
The following steps show how:
1. First, map the .htm extension to your asp.net runtime, which associates the URL extension with the DNN application.
Add the following entry to your web.config file, in this section of your web.config file:
<system.webserver><handlers>
...
</handlers></system.webserver>
.
Entry to add is:
<add type="System.Web.UI.PageHandlerFactory" requireAccess="Script" preCondition="integratedMode" path="*.htm" verb="GET,HEAD,POST,DEBUG" modules="ManagedPipelineHandler" name="HtmlHandler-Integrated"/>
Note this entry is for .htm - the
path attribute determines which extension you are mapping.
2. Save the web.config file. You can do a short test by requesting an existing URL, but with the new extension on the end. If you get the IIS 404 page, it is not mapped correctly. If you get the ASP.NET (or DNN) 404 page, you have mapped it correctly.
- Insert the setting for the new site extension into the applicable PortalSettings table by running this script in your Host->SQL page for the site:
delete from {databaseOwner}{objectQualifier}PortalSettings
where PortalId = x and SettingName = 'AUM_PageExtension'
delete from {databaseOwner}{objectQualifier}PortalSettings
where PortalId = x and SettingName = 'AUM_PageExtensionUsage'
insert into {databaseOwner}{objectQualifier}PortalSettings (PortalId, SettingName, SettingValue, CultureCode)
values
(x, 'AUM_PageExtension', '.htm', 'en-US')
insert into {databaseOwner}{objectQualifier}PortalSettings (PortalId, SettingName, SettingValue, CultureCode)
values
(x, 'AUM_PageExtensionUsage', 'always', 'en-US')
- Replace the 'x' values with the correct PortalD (and also check the CultureCode of 'en-US' if your site is a different culture)
- Check the 'Run as Script' checkbox and run the script. This script deletes any values you might have already for the site and adds the new ones (by default there will not be any, as it runs on the system defaults).
- If your DNN version is 7.1.x and you are changing the site extension to .htm or .html then you must also run the following script. If you have DNN 7.2 or later, or you're using another extension (like .asp or .php) you do not have to run this script.
The regex filter change script is:
delete from {databaseOwner}{objectQualifier}HostSettings where SettingName = 'AUM_IgnoreUrlRegex'
delete from {databaseOwner}{objectQualifier}POrtaLSettings where SettingName = 'AUM_IgnoreUrlRegex' and PortalId = x
insert into {databaseOwner}{objectQualifier}HostSettings (SEttingName, SettingValue)
values
('AUM_IgnoreUrlRegex', '(?<!linkclick\.aspx.+)(?:(?<!\?.+)(\.pdf$|\.gif$|\.png($|\?)|\.css($|\?)|\.js($|\?)|\.jpg$|\.axd($|\?)|\.swf$|\.flv$|\.ico$|\.xml($|\?)|\.txt$))')
insert into {databaseOwner}{objectQualifier}PortalSettings (PortalId, settingName, SettingValue, CultureCode)
values
(x, 'AUM_IgnoreUrlRegex', '(?<!linkclick\.aspx.+)(?:(?<!\?.+)(\.pdf$|\.gif$|\.png($|\?)|\.css($|\?)|\.js($|\?)|\.jpg$|\.axd($|\?)|\.swf$|\.flv$|\.ico$|\.xml($|\?)|\.txt$))', 'en-US')
This script changes the default regex filter which prevents URLs from being rewritten if they match. In DNN 7.1.x versions the filter includes .htm and .html, which will cause 404 errors for .html and .htm URLs when used for DNN pages.
3. Use the 'Tools' menu and click the 'Clear Cache' menu option.
4. Test the site to see that the DNN pages are now using .htm as an extension
NOTE: The above instructions are for running DNN 7 on ASP.NET 4 or later, using Integrated Pipeline mode.
This information applies to the DNN Platform, Evoq Content and Evoq Social solutions.