Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The page at example.co.in has a custom 404 page located at example.co.in/errors/404.html.

When I try accessing a non existent page from within the errors directory like this example.co.in/errors/baba (this page doesnt exist) I get the proper 404 page. However when I try to access a nonexistent page from a directory above or from any other directory I get the page but the image doesnt load.

The image is located in the errors directory same as the 404.html page.

<img src="rajni.jpg">

If I put the image in the main html directory (www) it works perfectly fine. The question is why does example.co.in/errors/baba work and example.co.in/baba not work?

EDIT: The links have been changed and wont work because of an SEO problem.

share|improve this question
    
post your .htaccess –  OneOfOne Sep 13 '13 at 23:55
    
im using virtual host configuration in apache no htaccess –  woofmeow Sep 13 '13 at 23:56
add comment

1 Answer

up vote 5 down vote accepted

You have a relative path to the <img> src. The actual image is at /errors/rajni.jpg. Thus the image will only load if the path is in /errors. To fix this, simply change the src:

<img src="/errors/rajni.jpg">

How apache serves it is different than how the browser requests it. The browser must make a separate HTTP request for every resource it downloads including the image. It makes one request to /not/a/page. Apache sees /not/a/page and returnsHTTP: 404; html=(basically). The browser parses HTML, displays, and seessrc=rajni.jpg. Then it makes another request:GET HTTP 1.1 /not/a/page/rajni.jpg`. Apache is happy to respond with another 404

share|improve this answer
    
I get that but why does it not work because the image is already in the same folder as the document ... why this weird path issue ? because its working from within the errors directory .. so whats causing it ? –  woofmeow Sep 13 '13 at 23:58
    
The browser is the one that's making the decision it's not aware that there is an error folder unless you tell it that specifically. –  rosscowar Sep 14 '13 at 0:02
    
@woofmeow With its current path (nothing) it will try to load from the same directory. So if you are already in errors it tries to load from /errors/ –  Explosion Pills Sep 14 '13 at 0:02
    
But when i enter a nonexistent page other than from /errors/ isn't apache supposed to serve the /errors/404.html page from the /errors/ directory ? Or am i understanding something wrong @ExplosionPills ,rosscowar –  woofmeow Sep 14 '13 at 0:08
1  
@woofmeow How apache serves it is different than how the browser requests it. The browser must make a separate HTTP request for every resource it downloads including the image. It makes one request to /not/a/page. Apache sees /not/a/page and returns HTTP: 404; html=<img src=rajni.jpg> (basically). The browser parses HTML, displays, and sees src=rajni.jpg. Then it makes another request: GET HTTP 1.1 /not/a/page/rajni.jpg. Apache is happy to respond with another 404 –  Explosion Pills Sep 14 '13 at 0:23
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.