SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Location
    Los Angeles, CA, USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess and ErrorDocument 404 & css

    Hi,
    I have called out on my .htaccess the ErrorDocument 404 going to the absolute path of the error404.php page. However, if I try to go to a non-existent directory or if it is misspelled, I do get my error page but it is not styled and is missing all the images. Why does this happen if on the htaccess doc says:
    ErrorDocument 404 http://www.myurl.com/error404.php ?

    The website is: http://tinyurl.com/kdsk2qv.

    It works fine if the 'page not found' is in the root directory where the error404.php page is located.
    Thanks so much,
    Janell

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    That's because the paths to your CSS files are relative. For example, you have

    Code:
    <link href="style.css" rel="stylesheet" type="text/css" />
    If I request yourdomain.com/does/not/exist/, the browser will look for /does/not/exist/style.css, which does not exist, because there is no style.css there, it's in the root of your domain.
    To fix this problem change the line before to

    Code:
    <link href="/style.css" rel="stylesheet" type="text/css" />
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Location
    Los Angeles, CA, USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ScallioXTX,
    Well, it seems that I needed to dig deeper as there is a handle_url.php that overrides the htaccess and it is a different error page that it serves up, not the error404.php. I am now just trying to find out how to make the link in the handle_url.php page send the visitor to the absolute path of the error page, but I don't really know php, so I am hopefully getting an answer from the folks that wrote the ECT Templates CMS .

    Thanks for your help. I did make the images and style sheet absolute paths, but I don't want to make all the links also absolute (that is now the problem, on the error page all the links try to go to that bad directory to find the page) as that is just more unnecessary code, so I am hoping that by making the path to the error page absolute that should take care of it, ... I hope!

    Thanks again,
    Janell

    Quote Originally Posted by ScallioXTX View Post
    That's because the paths to your CSS files are relative. For example, you have

    Code:
    <link href="style.css" rel="stylesheet" type="text/css" />
    If I request yourdomain.com/does/not/exist/, the browser will look for /does/not/exist/style.css, which does not exist, because there is no style.css there, it's in the root of your domain.
    To fix this problem change the line before to

    Code:
    <link href="/style.css" rel="stylesheet" type="text/css" />


Tags for this Thread

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
  •