How To: Custom 404 pages for DotNetNuke
November 13th, 2008, Erik HindsThere are two ways to add a custom 404 page for the DotNetNuke content management system. Your approach depends on what your hosting provider will allow.
1. Create a hidden 404 page in DNN. Add the URL for that page as a custom error page for 404 in IIS. Check with your host if you don’t have access to this information.
Here is a good post if you have IIS access and want to do it yourself: http://ask.enquiro.com/2008/how-to-create-a-custom-404-error-page-in-microsoft-iis/
2. Create an aspx file in the root directory. Create a new aspx page called 404.aspx. Also open the default.aspx file and a skin ascx file (you want the 404 page to look somewhat pretty, don’t you?)
Copy this line out of the DotNetNuke default.aspx and paste it in the 404.aspx (after the page declaration tag):
< %@ Register TagPrefix="dnn" Namespace="DotNetNuke.Common.Controls" Assembly="DotNetNuke" % >
Open your skin’s ascx file and copy ALL the skin token registrations; the ones that look like this:
< %@ Register TagPrefix="dnn" TagName="LANGUAGE" Src="~/Admin/Skins/Language.ascx" % >
In the < head > tags, paste the link to your skin’s CSS file. Ex:
< link href="Portals/0/Skins/standard/standard.css" rel="stylesheet" type="text/css" / >
In the form tag, paste the layout markup from your skin’s ascx file. The skin I chose just has a content pane that takes up the full width. Of course you can always create another CSS file and link to that to override your skins classes. In the content pane, put your 404 message:
< div id="ContentPane" class="content-pane" >
< h2 >
Sorry, the page you are looking for has been moved or cannot be found.< /h2 >
< script type=”text/javascript” >
var GOOG_FIXURL_LANG = ‘en’;
var GOOG_FIXURL_SITE = ‘http://www.mydomain.com/’;
< /script >
<script type=”text/javascript” src=”http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js”>< /script >
<p>
< a href=”/Home/Sitemap.aspx” title=”site map”>View the Site Map.</ a >
< /p >
< /div >
DON”T FORGET: Remove the visible=false attribute in your content pane div, otherwise you’ll have a blank page. You also may note that I have some extra JavaScript in there as well. I’m experimenting with enhanced 404s widget from Google’s webmaster tools.
I had to take option 2 recently and my host was able to point the 404’s to this new page, which looks like it’s just naturally part of my DNN site.