Loading...

All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

Version 9 (modified by mari@…, 4 years ago) (diff)

Adding iis 7.5 info

Custom 404 Handler

This library contains a custom 404 handler for your EPiServer CMS 4 or 5 project. It will replace the default 404 handler with one that you can change, in order for it to have a more consistent look with the rest of your site. It will also handle more 404 cases than the built-in handler.

Features

  • Custom 404 FileNotFound page to replace the built-in error page
  • A powerful CustomRedirects module thats extends the built-in ShortCurUrl function
  • An admin plugin that shows all the CustomRedirects defined
  • FallBack url handling that allows all 404 requests to be redirected to a back-end server only if the url exists on that server

This module has a more advanced url redirect feature than the built-in shortcut url feature in EPiServer. It handles extensions and querystring parameters too. If you have a lot of 404 errors in your logs, you can use this to redirect the user to the correct page. Especially useful if you move templates or pages around, or have just installed EPiServer and have a lot of old urls that is no longer available.

To ease the transition to EPiServer for your existing visitors, this module also contains a fallback handler that will check if a failed request can be sent to a backup system (your old site for an example.) Use with care, as it can make 404 requests slow, especially when spiders hit your site.

Screenshots

See what the 404 page can look like

Download

down.gif Download Now

Changing the notfound page

You can, and should, change the /bvn/filenotfound/notfound.aspx file to look somewhat like the rest of your site. The .aspx file is intentionally NOT an EPiServer template, to keep it clean and easy to troubleshoot. It uses text resources from the /lang directory. You can change the contents of the 404 page by editing the language files.

Please do not change and commit the notfound.aspx file directly in this library, make a copy of it and change that.

Keep the page simple, and if possible, avoid retrieving data from the database (like pages in EPiServer). The 404 page could be the result of a missing page in EPiServer and in worst case could lead to an infinite loop of 404 requests. Also make sure that your 404 handler itself does not trigger any new 404 errors by linking to graphics etc. that is missing (for the same reason).

Note! The source and configuration examples assume your site is a root relative site, not a virtual directory. If it is, you might have to change the code or configure the settings differently.

Custom Redirects

There are two types of redirects:

  1. Exact match The old url (the one not found) is matched. The redirect will be done to the new one.
  2. Beginning of string match In the code this is referred to as a wildcard match. This will be attemted if there is no exact match. All the old urls in the config file will be checked to see if they start with the same string as the url that cannot be found. This allow you to catch all not found urls that start with the same string, and redirect them to somewhere else, keeping the full url, but changing the domain. The path and query part of the url will be appended to the new url from the config file.

Example configuration file:

<redirects>
   <urls>
       <url>
           <!--
               This redirects within the same site.            
           -->
           <old>/templates/page.aspx?id=1234</old>
           <new>/travel</new>
       </url>
       <url>
           <!--
               This redirects to an old server. 
            -->
           <old>/mytemplates/form.aspx?id=3453</old>
           <new>http://www2.mysite.no/page13241.php</new>
       </url>
       <url>
           <!--
               Several out-dated urls can be redirected
               to the same new url.
           -->
           <old>/extra/ecp</old>
           <old>/extra/eec</old>
           <old>/templates/ecb.aspx?id=7556</old>
           <new>/wehavemoved</new>
       </url>
       <url>
           <!--
               Old shortcut url to
               new shortcut url!
           -->
           <old>/oldshortcuturl</old>
           <new>/newshortcuturl</new>
       </url>
       <url>
           <!-- Test to check that this should not
                go into a infinite loop -->
           <old>/demo1/notfoundtest</old>
           <new>/demo1/notfoundtest</new>
       </url>
       <url>
           <!-- You can also use site relative roots
                for your destination, as the redirect
                is done on the server.
           -->
           <old>/demo1/templates/Page.aspx?id=7411111</old>
           <new>~/search</new>
       </url>
       <url>
       <!-- Usually, when a "beginning of string" match is found, the path
            and querystring of the old url is appended to the new one. This
        can be used to redirect all pages below a given path to an old
        server. If you do not want the string beeing appended, set the
        onWildCardMatchSkipAppend to true.     
       -->
           <old onWildCardMatchSkipAppend="true">/our_business/markets/transport</old>
           <new>/en/Our-business/Markets/Automotive-and-transport/</new>
       </url>
   </urls>
</redirects>

There is also a plug-in for Admin mode to show the contents of this file.

Fallback Feature

In some cases, you want to keep the old site around for some time, to ease the transition. If you add a value to the EPsBvn404HandlerBackendRootUrl, the code will try to find the requested url on the backend server.

In a real life scenario you'd perhaps change the host name of the old site to www2.mysite.com, and roll out EPiServer on the www.mysite.com address. All browser favourites, links from other site etc. will then be broken (because of the new naming scheme of the site). With the fallback feature, an url like www.mysite.com/about/map.html would then automatically be redirected to www2.mysite.com/about/map.html, but only if that url exists. If the url is wrong or has been removed, the notfound page will be shown instead.

The Fallback feature invokes a web client request from the server to check if the backend actually recognizes the url. The result is then cached, and the next request for the same url will be redirected directly.

Note! This feature is only available in the EPiServer CMS 4 version.

Configuration

Note! For EPiServer CMS 5, the only appSetting you might want to configure is the EPsBvn404HandlerPage to point to your own 404 page. The module is enabled by default and should work out of the box as long as you have a CustomRedirects.config file in your site root directory. The CustomRedirects.config can be put in a VPP, but if the VPP is not a VirtualPathNativeProvider the contents of the file will be cached until the site is restarted (and not just until the file is changed.)

<appSettings>
    <!-- BEGIN 404 handler settings -->

        <!-- Where to look for custom redirects. Default value is: ~/CustomRedirects.xml -->
        <add key="EPsBvn404HandlerRedirectsXmlFile" value="~/CustomRedirects.config" />

        <!-- The 404 handler page. This is used by the http module when it redirects.
             Don't forget to set the 404 path in IIS to the same value in order to
             catch all 404 errors.
             Default value: "~/bvn/filenotfound/notfound.aspx"
         -->
        <add key="EPsBvn404HandlerPage" value="~/bvn/filenotfound/notfound.aspx" />

        <!-- Off, On, RemoteOnly
             Default value CMS 5: On
             Default value CMS 4: Off
        -->
        <add key="EPsBvn404HandlerMode" value="On" />

        <!-- If you have a backend webserver with the old site running, change
        this value with the backend server, like www2.mysite.com. The error
        handler will then try to find the requested page there.
        Default value: ""
        -->
        <add key="EPsBvn404HandlerBackendRootUrl" value="" />

    <!-- END 404 and Error handler settings -->
</appSettings>

IIS 5/6 Settings

Add the following settings to web.config

    <httpModules>
      <add name="Bvn404Handler" type="BVNetwork.FileNotFound.Handler.CustomFileNotFoundHandler, BVNetwork.EPi404" />
    </httpModules>

Change the custom 404 error.

  • Open IIS Manager, right click your site, select Properties
  • Select the Custom Errors tab
  • Find the 404 entry in the list, change the following settings:
    • Message type: Url
    • Url: /bvn/filenotfound/notfound.aspx
  • Select the Home Directory tab
  • Click the Configuration button
  • If the .aspx extension is not in the "Application extensions" list, add it it with the following settings:
    aspx extension configuration for IIS 6
    If the extension is already present, make sure it has the same settings as above.

IIS 7 / 7.5

Make sure you have the following configuration in your web.config file:

<configuration>
    ...
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            ...
            <add name="BVNetwork.EPi404"
                 type="BVNetwork.FileNotFound.Handler.CustomFileNotFoundHandler, BVNetwork.EPi404" />
        </modules>
        ...
        <httpErrors errorMode="Custom">
            <remove statusCode="404"
                    subStatusCode="-1" />
            <error statusCode="404"
                   prefixLanguageFilePath=""
                   path="/bvn/filenotfound/notfound.aspx"
                   responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

Make sure that "Error Pages" has been unlocked (Delegation set to Read/Write). You can edit this by selecting Feature Delegation in the iis root. Adding screenshot of feature delegation

Requirements

  • For EPiServer CMS 5
    • EPiServer CMS 5 R2 SP1 or newer
    • Visual Studio 2008 to compile the code
    • Unleash-It to use the post-build event for deployment (not a requirement)
  • For EPiServer CMS 4
    • EPiServer CMS 4.50 or newer
    • Visual Studio 2005 to compile the code
    • Unleash-It to use the post-build event for deployment

Support

As all code on EPiCode, use the ticket system or chat channel for support, and as always - use at your own risk.

Tickets for this component:

#1
Change custom redirect file to use another extension to hide it from browsing
#2
Allow wildcards in custom redirects
#3
404 handler should not trigger on images
#7
Use the SMTP settings in the correct way
#14
Need httpmodule to handle exceptions
#16
Interference with EPsErrorHandling?
#27
Translation in Swedish
#28
Missing httpModules section in documentation
#29
Make the redirect list editable for an administrator
#43
CMS 5
#128
Redirects does not work on IIS 6
#165
Redirects also affects EpiServer virtual admin interface
#198
The module returns status code 302
#202
Module ignoring querystrings when translating
#203
Mirroring?
#247
Custom redirects without wildcard
#248
Global exception logged after 404Handler redirects
#273
Default language always shown
#275
404 handler and globalization
#277
302 Always Follows 301?
#278
Show 404 enabled / disabled in gadget in dashboard
#279
404 should not be activated in edit mode for missing plugins
#280
New version?
#283
after installation through the deployment center I get an error
#284
Error after installation of 404Handler
#285
Add count for 404 hits when url are redirects custom redirects
#296
404Handler works very well on local IIS, but it does not work on a remote IIS Server
#302
Delete suggestions in the 404 handler
#303
issue with redirect
#306
overwriting existing redirect on enterprise
#311
404 handler for CMS 6.0 (and NOT 6.2)
#314
How to specify redirect URLs for different domains?
#319
Add suggestions filters
#320
If we add a trailing /, it gets redirected wrongly
#322
custom handler not working together with the redirects
#323
404 suggestions for pages ending in /null
#324
Norwegian letters in url
#327
Suggestions with /null at the end of a valid URL>
#333
Should the BVNetwork.FileNotFound.Redirects.RedirectsXmlParser constructor log an error if the Custom redirects file does not exist
#345
Restricting Custom Redirects Manager gadget to certain roles
#346
Gadget disappears from Dashboard
#349
Get this error
#350
Question: Delete all suggestions from database?
#351
Move IgnoredResourceExtensions to web.config?
#352
After installing NuGet package, references not added to 404Handler DLLs
#353
Trackhandler issue
#354
Delete suggestions but not custom redirects : Episerver 6
#355
Gadget visible but not working

Ask a question

Requires login.


Report a bug

Requires login.


Add a feature request

Requires login.


Attachments