Forum Moderators: phranque

Message Too Old, No Replies

custom 404 page works fine, but in subdirectory images missing

Any ideas?

         

brizad

6:40 am on Sep 16, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



This seems kind of odd to me and I am sure there is a simple answer...I just can't figure it out.

On my hosting account you can build custom 404 pages through the cpanel. I have one there and it works fine for any pages in /.

However, I have just made some pages in a subdirectory and I noticed that if a 404 comes up from there the text of the page is all there but the images are not.

Any ideas why this is happening? I already tried to put a separate images file in the subdirectory but it didn't work.

keyplyr

8:11 am on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To be sure images display in subdirectories, use full paths for the image tags.

example: <img src="http://www.domain.com/images/file.gif" border="0"..... and so on

stapel

1:55 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem stems from the fact that you don't know from what direction the 404 will be coming. Suppose you have a file structure something like:

/home/
/home/images/
/home/subdirectory/

When you get a 404 error from inside "/home/subdirectory/", the browser stays inside that directory. But if your 404 page was written with links relative to "/home/", then the page will be looking for images in "/home/images/": "/images/imagename.gif", say. But the URL, because of your being inside the subdirectory, will attempt to resolve as "/subdirectory/images/imagename.gif". Since the file doesn't exist in that location, it can't be displayed.

This is why it is recommended that, for 404 (and other) error pages, you use absolute links. That way, images will display as desired, and you can "pop out" to the correct location when you click a link.

Hope that helps.

Eliz.

brizad

10:52 pm on Sep 16, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yep that was it. Thanks.

jdMorgan

11:00 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Server-relative links should be OK, too:

<img src="/images/file.gif">

Jim