Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Redirect 404 Page

Discussion in 'General Discussion' started by Nerd Boy Inc, Dec 1, 2011.

  1. Nerd Boy Inc

    Nerd Boy Inc Registered

    Apr 9, 2011
    Likes Received:
    Trophy Points:
    Dear All,

    I know I can edit a 404 Page, but what I need to do is to be able to change what page is actually called when a 404 happens. I want to be able to call something besides 404.shtml (or whatever the real name is). I want to be able to call another page that is a script that will run when a 404 happens.

    How / where can I change this at the Vhost level?

    Thank you,

    Jeff Collins
    Nerd Boy Inc
  2. eUKAlexP

    eUKAlexP Member

    Jan 12, 2009
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    DataCenter Provider
    Hi Jeff Collins,
    ErrorDocument Directive is comes in Apache core module. You can add an ErrorDocument handler that specifies the exact numeric code and the name of the file to serve up (or CGI script to run) when that error is encountered in apache configuration file or .htaccess file.
    Here's how that might well look:

    ErrorDocument 3DigitErrorCode /path/to/your/error/file/or/script

    The 3-Digits error codes are as follows:
    Error 400 Bad Request
    Error 401 Authorization Required
    Error 403 Forbidden
    Error 404 Missing
    Error 500 Server Configuration Error

    Thus the following line tells the server to run the error404.cgi script if the server cannot find the requested page.

    ErrorDocument 404 /cgi-bin/error404.cgi

    This way, you can trap as many errors as you want.

    Below is an example of a .htaccess file, just copy and paste into your file, but change the paths:

    ErrorDocument 404 /path/to/your/error/file/or/script
    ErrorDocument 500 /path/to/your/error/file/or/script
    ErrorDocument 403 /path/to/your/error/file/or/script

    Additionally, the special value default can be used to specify Apache's simple hardcoded message. While not required under normal circumstances, default will restore Apache's simple hardcoded message for configurations that would otherwise inherit an existing ErrorDocument.

    ErrorDocument 404 /cgi-bin/

    <Directory /web/docs>
    ErrorDocument 404 default
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice