Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- htaccess, 404 page and relative paths
April 12, 2005, 5:31 pm
rate this thread
same layout as the rest of my site and specified some corresponding
lines in the .htaccess file in the root directory of the site.
It works like a dream, so I was feeling very professional :),
The directory structure of the site is like:
subdirectory containing some standard images
All files in all subdirectories refer to the stylesheet in the root and
some standard header images in the 'images' directory, using the
appropriate relative paths like ../stylesheet etc. That also applies to
Url: domain/wrongname gives the correct 404page
Url: domain/subdirectory/wrongname gives the correct 404page
Url: domain/subdirectory/subsubdirectory/wrongname gives the 404-page
with broken links to the headerimages and without the style.
I fixed it by using the absolute addresses in the 404page, so the
problem is over. But for the sake of the learning-curve: what could be
the explanation of the variable "path-level" of the called 404page?
Re: htaccess, 404 page and relative paths
The 404 page is being served instead of the requested page - look at
the location bar of your browser and you'll see
So the browser will resolve all relative URLs relative to the
404.htm may contain ../stylesheet. Where does that resolve to for the
domain/wrongname --> domain/../stylesheet which is error corrected to
domain/subdirectory/wrongname --> domain/subdirectory/../stylesheet
which is domain/stylesheet
domain/subdirectory/subsubdirectory/../stylesheet which is
You can use site root relative URLs instead of absolute URLs. So
href="/stylesheet" in your case. This will always be resolved relative
to the root of the site and hence will always work regardless of where
the 404 document is returned.
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor