1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom Error Pages with Apache

Discussion in 'Webmaster Tutorials' started by Josh, Jan 25, 2007.

  1. Josh

    Josh New Member

    Information about Status Codes: HTTP/1.1: Status Code Definitions


    In this tutorial I will be showing you how to be creating error pages for the following: 400, 401, 403, 404, 500.
    You can find what these mean at second post. ;)

    10.4.1 400 Bad Request
    10.4.2 401 Unauthorized
    10.4.4 403 Forbidden
    10.4.5 404 Not Found
    10.5.1 500 Internal Server Error

    Now, we simply create a file .htaccess (I have uploaded it in a .zip since Windows can not create one by default.

    Now, open it up and enter the following lines:

    Code:
    ErrorDocument 400 [url]http://www.domain.com/error.php[/url]
    ErrorDocument 401 [url]http://www.domain.com/error.php[/url]
    ErrorDocument 403 [url]http://www.domain.com/error.php[/url]
    ErrorDocument 404 [url]http://www.domain.com/error.php[/url]
    ErrorDocument 500 [url]http://www.domain.com/error.php[/url]
    Changing the domain and the error.php to what you what your domain is.

    Now simply upload it to your host, and now when someone visits a page that cannot be found for example (404) they will get the error page you created!

    Neat huh!

    Comments and questions are welcome.

    10.4.1 400 Bad Request

    The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

    10.4.2 401 Unauthorized

    The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information. HTTP access authentication is explained in "HTTP Authentication: Basic and Digest Access Authentication"

    10.4.4 403 Forbidden

    The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.

    10.4.5 404 Not Found

    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.

    10.5.1 500 Internal Server Error

    The server encountered an unexpected condition which prevented it from fulfilling the request.



    Please note, I posted this on another forum I visit.
     
    • Like Like x 2
  2. Tomar

    Tomar New Member

    Thats nice tips It means we can redirect that pares to create by us.
    thanks!
     
  3. nick_mayhem

    nick_mayhem New Member

    I saw one online error pages creator. Forgot the link but you can google it and it was really nice one.
     
  4. OhioTom76

    OhioTom76 Guest

    I just discovered something with one of the web hosts I use, Fatcow.com - they are actually pimping their customers 404 pages with injected ads. The option to turn this off is buried away within their account settings and they are not very upfront about this.

    At first I thought I had some sort of adware on my system causing them to show up, but after several hours of scans, I discovered it was happening on their end.

    This is all the more reason to create your own custom 404 pages instead.
     
  5. Deathstarr

    Deathstarr
    Administrator
    Staff Member Administrative Moderator Premium

    Yeah getting your provider 404 pages is terrible. Didnt know they were still doing this..
     

Share This Page