Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

    .htaccess errorpages path problems

    Hi guys,

    I have my .htaccess file in a subdirectory from the server root. I want to configure the server to use custom error pages. However, I can't seem to make it use the right path.

    Following is my directory structure:

    Root --> Folder1 --> .htaccess
    Root --> Folder1 --> errors --> error.php


    I want to make it so that the .htaccess knows that the 404 error page is located in errors --> error.php - thus avoid stating an absolute path.

    This is what I've got in my htaccess:

    ErrorDocument 404 ./errors/errors.php

    However, whenever I go to a page that doesn't exist, all I get is a white page with the following text: ./errors/errors.php. The url doesn't change to the error pages url.

    If I, for instance, change the path in the .htacces file to: /errors/errors.php (without a leading dot), I get the default error page displayed.

    What do I do wrong? It seems like I've tried everything with the relative path thing.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Nobody has a clue?

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    ErrorDocument expects the path argument to be either a fully qualified URI, a path relative to root or a string. Since a value beginning with . is neither a path relative to root or a fully qualified URI, it assumes it's a string, hence the fact you get it output on the page. The /errors/errors.php value would look in the root directory for that path, which doesn't exist, so it would fall back to the server default.

    You would need to set it as...

    /Folder1/errors/error.php

  • Users who have thanked Cags for this post:

    CaptainB (11-06-2011)

  • #4
    Regular Coder
    Join Date
    Mar 2010
    Posts
    198
    Thanks
    78
    Thanked 5 Times in 5 Posts
    Heres a extra tip:

    Make sure you donít specify a full URL to your 404 page.
    For example something like "http://www.example.com/404.html"
    This will cause your server to return the wrong response code, and will actually make it seem like the page was found correctly.

    If you specify the path to your file relative to the root, like "/404.html",
    you wonít have these problems.

    Itís also a good idea to add the code
    Code:
    <meta name="robots" content="noindex">
    to the <head> section of your 404 page, so that search engine robots donít add it to their indexes.

    Here is a list of some common HTTP error codes:
    Code:
    400 Bad Request
    401 Unauthorized
    403 Forbidden
    404 Not Found
    410 Gone
    500 Internal Server Error
    Example use:
    Code:
    ErrorDocument <error_code>  /<your_page>.html

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Caigs: Thank you for that explanation! I did not know that the url had to be relative to the root. I guess there's no way to automatically let the error page know if the path to it changes - for instance, if I move it one level up or down relative to the root?

    Conware: Thank you for the additional details - got it covered!


  •  

    Posting Permissions

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