Forum Moderators: phranque

Message Too Old, No Replies

htaccess and 404

         

janbeeu

5:23 am on Feb 9, 2006 (gmt 0)

10+ Year Member



In my rootdirectory I have an htaccess with some denys and redirects in it but also ErrorDocument 404 /404.htm

In my www directory with the folders and files of the site where also my 404 page is, I also have an htaccess with

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?anothersite.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?images.google.com(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp¦mp3¦wav)$ [mysite.com...] [R,L]

no1.gif is the image returned when someone hotlinks to one of my site images.

The 404 page takes its images from a a file in the www directory called ex. This ex-file has an htaccess file with

RewriteEngine off

When for instance in Google images, I click on an old image of my site I know isn't there anymore, Google displays the thumb of the image with my 404 underneath. When I click on the thumbnail, my no1.gif image is shown. So this is al working fine.

When I enter the url of a page that doesn't exist anymore or I mistype the url, it displays my 404 fine. However when I do the same with the url of a file in a subdirectory of this www directory, it displays the 404 with broken link images.

Where do I go wrong?

jdMorgan

6:08 am on Feb 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two problems:

First, the custom 404 error page is served as if it were the content of the originally-requested URL. The browser will therefore resolve any relative URLs on the 404 page as relative to the originally-requested (bad) URL. So, all links in the 404 page code should be server-relative or canonical -- that is, <IMG src="/image.gif"> or <IMG src="http://www.example.com/image.gif">. Don't try to use <IMG SRC="image.gif">

Second, I'd recommend that you keep all custom error pages as simple as possible -- No includes, no images, no scripts. This will prevent a small problem on the site (like a missing file) from becoming a much larger problem because it minimizes the chance that the error-reporting mechanism itself will depend on a broken resource. All by way of saying, "Error pages don't need images, and the site will be more reliable without them."

Jim

janbeeu

6:27 am on Feb 9, 2006 (gmt 0)

10+ Year Member



Why make it difficult when it could be simple huh? :-)
Thanks JP.