Forum Moderators: open
This is copied from a newsletter:
The 404 Page Fix
The best 404 pages explain that the specific information they
were looking for no longer exists, but then offer them several
links into the other sections of your site.
Once you've developed a custom 404 page (which is just a basic
html page), name it "custom_page.html" and upload it to your
server. Then, locate the .htaccess file on your server. It's
located in different places, depending on your server software
and operating system, but it will be there somewhere.
Edit this file so that it contains the following one line command:
ErrorDocument 404 [yoursite.com...]
Obviously, you'll need to change "yoursite.com" to your real
URL.
I'd like my custom 404 to say something like "you're looking for <foobar.html>. This does not exist...."
What's the variable name that will have the name of the referring file?
thanks!
Anyone know what I'm doing wrong?
Thanks!
Well I setup a test and I think I might know what the problem is.
If you've set up .htaccess as Hunter says, you might get the name of the 404doc in REQUEST_URI.
My 404 doc is called missing.html - SSI enabled on .html docs.
I tried it 2 ways, one with the absolute path - and I got the same result you did. The second method was to refer to a local path (/missing.html)
ErrorDocument 404 /missing.html
This got the original requested document in REQUEST_URI and it works.
HTTP_REFERER will only have a value if the user clicked on a link somewhere to get to the page (and then sometimes it will still be blank as in the case of Opera where you can turn off Referer strings).
[added]
See the notes here:
ErrorDocument [httpd.apache.org]
A fully qualified url (with http:// in front) will cause a server redirect to the 404 document, even if it is on the same server, which is not what you want.
I didn't understand your reference to missing.html being ssi enabled. I can only get it to work if I use the .shtml extension.
I also uncovered a bug in my custom_404 page. I have links on my page and a message inviting the user to click on a link. However, my links were relative, <a href="clickme.html"> ...
So if a user looked for mypage/images/foobar.fuzzbah, when they got the error, the link was for mypage/images/clickme.html which doesn't exist. There's no way out!
So the solution is to make my links absolute <a href="/clickme.html"> (preceded by a slash). Is that absolute, or relative to home?
Anyhow, thanks again for your help. :)