Reply
Golden
emarcus
Posts: 232
Registered: 05-28-2010
0

No more '404 Not Found's

[ Edited ]

(Originally posted March 21, 2011)

 

About this extension

  • Author:       OwenGarrett
  • Released:  21/03/2011 - 9:10am
  • License:     BSD

 

When you move content around a web site, links break. Even if you've patched up all your internal links, site visitors from external links, outdated search results and people's bookmarks will be broken and return a '404 Not Found' error.

 

404banner

 

This extension intercepts any 404 errors from your web servers and performs the following actions:

  • If the request was for an image, it replaces the response with a small, blank image
  • If the request was for an HTML document, it prompts the browser to try accessing the next page up in the URL tree
  • If the request was for another type of document, the extension sends back a very basic ‘404’ message

For example, if a user  tries to access the (missing) page http://example.com/foo/bar/wibble.html, the extension will automatically prompt his browser to try /foo/bar, /foo and ultimately / until it gets a suitable response.

 

For more information, please refer to the article ‘No more 404 Not Found...?

 

Installing the Extension

 

Requirements:

 

This extension has been tested against Zeus Traffic Manager 7.1, and should function without problems with most earlier releases of Zeus Traffic Manager.

 

Installation:

 

Download the extension and extract the 404capture.zts TrafficScript rule.  Open in an editor, and paste the contents into a new response rule:

 

404-1

 

Verify that the extension is functioning correctly by trying to access a page through the traffic manager that would normally give a ‘404 Not Found’ error message, such as http://your.site.com/this/does/not/exist.html.

 

For reference, the source of the 404capture.zts rule is replicated below: 



    if( http.getResponseCode() != 404 ) break;

    # We have a 404 - how will we handle it?
    $path = http.getPath();
    string.regexmatch( $path, '.*(\.[^/]*)$' );
    $ext  = $1;

    # If it's an image request, send an empty gif
    if( $ext == ".gif" || $ext == ".jpg" || $ext == ".jpeg" || $ext == ".png" ) {
       http.sendResponse( "200 OK", "image/gif",
          "GIF89a\x01\x00\x01\x00\x80\xff\x00\xff\xff\xff\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3b",
          "" );
    }

    # if it's an HTML or index file, work up the URL tree
    if( $ext == ".html" || $ext == ".htm" || $ext == "" ) {
       # If we're on the home page, there's nothing further we can do
       if( $path == "/" ) break;
       
       if( string.endsWith( $path, "/" ) ) $path = string.drop( $path, 1 );
     
       $i = string.findr( $path, "/" );
       $path = string.substring( $path, 0, $i-1 )."/";
     
       http.redirect( $path );
    }
       
    # otherwise, it's some other sort of media (css, js, video etc) so just
    # send a bare '404' response
    http.sendResponse( "404", "text/plain", "", "" );

 

 Download this extension below:

‬‪‬‪‬‪