Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache error documents (404 etc) 2

Status
Not open for further replies.

wellmad

Technical User
Apr 23, 2004
11
GB
Hi,

I'm about to create some customised error pages to be displayed when a requested URL is not found, etc but I've noticed something.

I'm running apache locally on a Win XP Pro machine to test PHP scripts etc and use IE6 as a test browser. I'm using the default apache install and I haven't messed about with the config file other than to set the document root and run PHP and MySQL.

What I'm finding is that when I request a page that isn't there, instead of getting an Apache error page, I get an Internet Explorer error page instead. This means that I cannot even begin creating my own error pages!

How can I change this behaviour and make apache serve an error page?
 
Apache will serve an error page only if set up to do so. See
When custom error pages are proerly set up, in the case of a 404, you're telling apache to serve a a particular page when this error occurs. The browser will display this particular 'error page' just like any other page. Hopefully the error page will have some information about what caused it to be served - like "The page you requested was not found, so I've been instructed to display this one instead".

You're seeing the IE generated message because apache hasn't been told to do anything other than tell IE 'not found'.
 
Sorry, but it's still not working... I've uncommented the ErrorDocument directive and added the following url to my custom error page as such:

ErrorDocument 404 /notfoundpage.html

But still I get the IE 404 message. I've looked through the link in your post and I think I've done everything I should have but like I say, it isn't working.

I'm sure ther's something else, apache error documents are so distinctive, you can tell straight away when surfing if the site you're on uses Apache because of the error pages, but I'm don't even get the default ones. I thought it might be something to do with IE but it doesn't work with Mozilla either
 
For testing, create a folder under your document root that contains 1 simple html file. Next, add the following container to your httpd.conf

<Directory real path here>
AllowOverride All
Order allow,deny
Allow from all
ErrorDocument 404 "There's nothing here"
</Directory>

After restarting apache, try accessing the simple html file to make sure everything's working. If so, then access some ficticous .html file in that directory. Do you get the error?
 
Hi,

I did as instructed and added the above code to my conf file and a test page in the new folder. I was able to access the test page fine, but when trying to access a fictitous page, I still get the IE 404 message, not the line saying "There's nothing here"

 
I have to ask: Did you restart apache after making the change to the .conf file?
 
Of course =) Actually, I stopped it and then started it just to be sure...
 
Well, it appears that I'm guilty of leading you astray. Apparently, I tested the configuration that I posted above with Firefox (where it works). Apparently for a custom error document to be displayed in IE 5.x+, the error document needs to be greater than 512 bytes. This interesting article is for a way to do this with IIS, but look just below the reference to RFC 2616


This one I definately tested with IE6 & it works as expected:
Code:
<Directory [COLOR=green][i]real path here[/i][/color]>
 AllowOverride All
 Order allow,deny
 Allow from all
 ErrorDocument 404 [URL unfurl="true"]http://www.msnbc.com[/URL]
</Directory>
 
Thanks smah, that's got it working. First I switched off the 'show friendly errors' in IE and tested it as it was and it worked, then I increased the size of the error page to 512+ bytes, switched the setting back on and tested it again, and it worked!

brilliant =)
 
Glad it's working, I was beginning to worry that something was wrong with your apache installation. I wasn't aware of the 512 byte thing before now either. Unfortunately, there's no way to turn off IE's friendly error messages from the server. So it seems that some of apache's functionality can be lost with IE 5&6 users. The good news is that I just tested this function with the current IE7 beta & it works properly; even the simple text phrase error is displayed when it should be.
 
Excellent, glad to hear MS are correcting basic things like this.

I was beginning to think I had some kind of problem wih my PC in general, this wasn't working (I thought) and I have other weird little niggly problems like not being able to view the source of any web page with IE...but I'm glad it was something easy =)

Thanks again for all your help.
 
For the view source thing, clearing your Temporary Internet Files usually takes care of it.
 
Ok guys I want to take the this one step further. I have multiple sites on my webserver. I own and cotrol the webserver. I am brand new to apache, or at least modifying. I want the standard 404 for all the sites except one. If I have to i can have a script written for the 404 if i can make the page a php page but i don't really want to.

I am running a mac OS 10.3 server running apache 1.3.

I guess my question is as follows. Can I have multiple error pages for the same error. Depending on site that gets the error.

Thanks early
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top