Web Hosting Forums

Results 1 to 12 of 12

This is a discussion on 404 error in the Hosting Talk & Chit-chat forum
How do I create a custom error page to display when a user enters a wrong URL, an outdated URL or when the user is ...

  1. #1
    Loyal Client
    Join Date
    May 2004
    Location
    Florida
    Posts
    30

    404 error

    How do I create a custom error page to display when a user enters a wrong URL, an outdated URL or when the user is not authorized to access a specific directory? I've tried, under error pages in Services, to personalize a page, save it then try it and nothing changes. What am I doing wrong? And what is the toggle button "Select tage to insert" do?

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    You should be able to edit them in the CPanel, but I've never tried using those editors, so I don't know how well they work. My guess is that some clients are using them and I've never seen anything posted here about problems, so if you are having trouble (and you want to use that method) maybe a support ticket is in order.

    The other method (which I use on my site) is to create custom error pages as you would any other pages in on your site. I keep mine in a directory called "errors" inside my public_html directory, but where you keep them (inside public_html) doesn't much matter. Then add an ErrorDocument line to your .htaccess file for each of the error types that you've created files for. Here is an example from my .htaccess:

    ErrorDocument 404 /errors/404.php

    As for the the "Select a tag to insert" field in .htaccess, that lets you add certain dynamic information to the message that is displayed on the error page, such as the page that the link the visitor clicked on that generated the error, the visitor's IP address, the URL they were trying to get to, etc.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL 2010

  4. #4
    Old Hillbilly Connie's Avatar
    Join Date
    Sep 2001
    Location
    Hills of Missouri
    Posts
    2,491

    Re: 404 error

    Originally posted by Patti
    How do I create a custom error page to display when a user enters a wrong URL, an outdated URL or when the user is not authorized to access a specific directory? I've tried, under error pages in Services, to personalize a page, save it then try it and nothing changes. What am I doing wrong? And what is the toggle button "Select tage to insert" do?

    This can be set up through the CP. All CP does is create
    a 404.shtml page so you can probably do the same without using CP.
    A custom error page has to be over a certain size or IE won't recognize
    it. This is the quick and easy way to do it. There is a problem. If
    someone clicks on a thumbnail and the enlargement is not there they will
    get your custom error page.

    My Custom Error Page

    If you want to have links on a custom shtml page you will need to add a / in front
    of the link to get back to an htm or html page. Example /page.htm.

    I think Jason may have a better solution. Using .htaccess you could create
    different error files for different errors. Page not found, Image not found.
    I will look into his method when I have a little more time.

  5. #5
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,414
    You can make a custom page for any server error. See HTTP/1.1: Status Code Definitions for a numerical list. The most typical are 401, 403, 404, and 500.

    So as mentioned before, create in your public root directory an .htaccess file with the following:

    ErrorDocument 401 /path/to/error401.html
    ErrorDocument 403 /path/to/error403.html
    ErrorDocument 404 /path/to/error404.html
    ErrorDocument 500 /path/to/error500.html

    Then create the corresponding errorNUMBER.html files and give them the following permissions:
    -rw-r--r--

    And use WinSCP as mentioned by Vin numerous times. It's much easier to use than cPanel IMO, and the knowledge you get from using it (WinSCP) is portable to any server; consequently, you won't be limited by the cPanel web application.

  6. #6
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661

    Re: Re: 404 error

    Originally posted by clssam

    My Custom Error Page
    That's pretty! I like that one, Connie, even though it isn't black...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL 2010

  7. #7
    Old Hillbilly Connie's Avatar
    Join Date
    Sep 2001
    Location
    Hills of Missouri
    Posts
    2,491
    Hey Spath,

    If you use an shtml page as the error page it does not require an .htaccess entry.


    Thanks for the detailed info about how to do this with html or I assume htm pages
    using .htaccess.

    I do have a question. If I understood Jason's post correctly you could have different
    404 error page results displayed using .htaccess. An error page for html pages or a different page
    for an image. I'm pressing the limits of my memory here but this subject came up a long
    time ago. If I remember correctly Jason indicated at that time that he used a different
    error page for images which may have clouded my interpretation of what he posted
    in this thread. On the other hand my memory is not to great if the event is more than
    a day old.

    My main concern is 404 errors. It would be great if you could have a different error
    displayed for htm pages and images.


  8. #8
    Old Hillbilly Connie's Avatar
    Join Date
    Sep 2001
    Location
    Hills of Missouri
    Posts
    2,491

    Re: Re: Re: 404 error

    Originally posted by Vin DSL
    That's pretty! I like that one, Connie, even though it isn't black...
    Your right it's not black.


  9. #9
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Connie,

    Your memory is better than you think. I remember discussing this topic before, but it was a very long time ago.

    You can define one error page for each status code in an .htaccess file. You can, however, have .htaccess files in more than one directory. Anything you define in an .htaccess file overrides what was defined in any of the .htaccess files in levels higer than the current one. So if you have one file in public_html and another in public_html/stuff anything that is defined in public_html will apply to stuff unless it has been redefined in stuff (hope that makes sense).

    What I have done on a couple of the sites that I maintain is put an .htaccess file in my images directory where I redefine my ErrorDocument for 404's to be an image.

    For example:

    In public_html/.htaccess:

    ErrorDocument 404 /errors/404.php

    In public_html/images/.htaccess

    ErrorDocument 404 /images/404.jpg

    That way, if an <img> tag contains an incorrect "src" attribute the user will see an image instead of a broken image icon from the browser (as long as the link is pointing at the images directory). Of course, if someone tries to link to a non-existant page in the images directory they'll get the image as the 404 page instead of the an html page.

    Hope this helps.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  10. #10
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,414
    Originally posted by clssam - quotes in bold
    If you use an shtml page as the error page it does not require an .htaccess entry.
    I hadn't really thought about shtml. I try to avoid SSI processed files whenever possible because for me, it just introduces unnecessary processing overhead. I like to present straight "read and reguritate" text files whenever possible, especially on a shared server. But if you use SSI in a template file of sorts, then the shtml way works too, as you well know.

    Thanks for the detailed info about how to do this with html or I assume htm pages using .htaccess.
    No problem and yes, you are right. All browsers interpret .htm and .html files the same unless you go out of your way to redefine the mime-type. No one is going to do that for hypertext extensions.

    If I understood Jason's post correctly you could have different 404 error page results displayed using .htaccess. An error page for html pages or a different page for an image.
    I'm not aware of such a 404 image vs xHTMx differentiation from a single .htaccess file. You can define any error document, image, or script to serve as the returned error file but that isn't really what you desribed. See Apache ErrorDocument Directive. My only guess is that you place the .htaccess file I described in the public root, and then you create a new .htaccess file in the images directory indicating another 404 error but specifying that the missing file is an image. The .htaccess rules in the second .htaccess file supercede its predecessor in the public root if the Apache server allows .htaccess override enable - Jaguar's servers do.

    So to test an easy way:
    1- Create/edit public root .htaccess with
    ErrorDocument 404 /path/to/error404.htm(l)
    Assign permissions of -rw-r--r--

    2- Create file /path/to/error404.htm(l)
    Assign permissions of -rw-r--r--

    3- cd to image directory

    4- Create/edit top image directory .htaccess with
    ErrorDocument 404 "Sorry, you requested an image that is not available
    Assign permissions of -rw-r--r--

    My main concern is 404 errors. It would be great if you could have a different error displayed for htm pages and images.
    Try the above. I think it could work but I've never done it to be sure. I'm going to assume that the first 404 error encountered will result in the appropriate warning.
    Last edited by Spathiphyllum; 05-31-2004 at 08:43 PM.

  11. #11
    Old Hillbilly Connie's Avatar
    Join Date
    Sep 2001
    Location
    Hills of Missouri
    Posts
    2,491
    Septh you and Jason must have posted about the same time. See his replyl. I think your conclusions are in agreement with Jasons.

    If a error page is set up through CP the extenison will be shtml. Other than the 404 error page I do not use shmtl.

    I do have the server parse htm html files. The basic lay out of my web site depends on SSI.

    Based on your input and Jasons it looks like it's a matter of Mod Rewrite. to deliver a specifc file for an error if there is not a shtml file availabel.

    Thanks to both of you for the input.

  12. #12
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,414
    Originally posted by clssam
    Septh you and Jason must have posted about the same time...
    Based on your input and Jasons it looks like it's a matter of Mod Rewrite to deliver a specifc file for an error if there is not a shtml file availabel.
    What are the odds - posting within seconds of each other. A little cross-pollination happening here.

    Not to be petty but I don't want to introduce confusion here. ModRewrite isn't actually resolving the request. The Apache server is using a more basic routine to return a hard reference based on absence of a file in a particular directory. The benefit is that you do not need a modrewrite enabled version of Apache for this "trick" to work. Any Apache server that allows .htaccess override can modify the default server settings.

    One disadvantage of referencing an image file directly rather than an shtml/html with the same image coded within the page is that it is slightly less browser friendly IMO. Browsers prefer to read text over images for layout formatting. Also, I think you may have issues with the image not appearing if you have hot-link prevention enabled. Depends on how the image is requested and the rule used.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •