dotnetnukedotnetnuke-9

DNN return parent page instead of 404 page, how to return 404?


We have a normal DNN installation (v09.00.02 366) and we set a 404 page using the "Default Pages" under the site settings.

There's this odd behavior where DNN returns the content of the parent page instead of returning a 404 page when you browse to an non-existent page.

/parent/child => returns the content of /parent

The child page doesn't exist so it should return the 404 page with HTTP status code 404.
How can we change the behavior to follow the desired behavior?


Solution

  • The most common instances that a not-found page will properly return a 404 error in DNN are listed below:

    There are other select instances, but this is the gist of it. This is because of the dynamic nature of DNN. When a module is added to a page, DNN doesn't know if this module is dynamically creating its own URL's or not.

    Examples of this include blog and news modules. A non-technical content editor needs to be able to create a new blog post or news item and it should have its own unique URL.

    Examples:

    Looking at the examples above, DNN couldn't safely redirect as a HTTP 404 error since the pages actually do exist, but only as URL's that are then dynamically used to load custom data from the module on the page.

    A solution for this would be to create your own URL provider, which you could base on the one found in the core of DNN.

    Another solution would be to ensure that you set stand-alone pages (those without dynamic modules) to have a canonical URL specified. You can do this in the page's respective settings.

    More information about the URL provider at the time of release is in the blog post below.

    https://www.dnnsoftware.com/community-blog/cid/154518/page-not-found-404-error-handling-in-dnn

    On a side note, many of the URL provider features don't have a UI to control them. You can see the URL provider settings by running the following queries to see what the settings are.

    -- the highest-level settings
    SELECT * FROM [dbo].[HostSettings] WHERE [SettingName] LIKE '%aum_%' ORDER BY [SettingName];
    -- setttings for each website, overriding the host-level settings
    SELECT * FROM [dbo].[PortalSettings] WHERE [SettingName] LIKE '%aum_%' ORDER BY [PortalId], [SettingName];