dgb001
asked on
Change response code from 404 to 200
Hi,
On a couple of freebie servers I notice that when a page doesn't exist (if being spidered for example) then the host doesn't actually return an error 404, but does still produce a page, which effectively has the URL of the page requested. i.e. it seems to be able to throw away the 404 response before coughing up the output. I don't mean a re-direct, or similar, but actually changing the 404 response into (what I guess would be) a 200 response. I know that most servers don't do that, but I'm not even sure how it can be done unless it's some sort of Apache mod - any good info appreciated.
Regards,
D
On a couple of freebie servers I notice that when a page doesn't exist (if being spidered for example) then the host doesn't actually return an error 404, but does still produce a page, which effectively has the URL of the page requested. i.e. it seems to be able to throw away the 404 response before coughing up the output. I don't mean a re-direct, or similar, but actually changing the 404 response into (what I guess would be) a 200 response. I know that most servers don't do that, but I'm not even sure how it can be done unless it's some sort of Apache mod - any good info appreciated.
Regards,
D
ASKER
Looks pretty cool....gimme a while to digest it and I'll get back to you. Thx a lot.
D
D
ASKER
Sorry to be so dense...so it goes something like this...
in access.conf (or possibly .htaccess?) I point the 404 error code to a script (any old script) in cgi-bin, which will execute each time a 404 occurs...and then in the script (we'll call it 404.pl for now) it will grab the referring page (?) and then we can do something with it...such as the thing with the apache mod_asis (which is the bit that kinda means nothing to me at the moment)....so how/where do I use the bit of code above with:
Status: 200 Now where did I leave that URL
Location: http://xyz.abc.com/foo/bar.html
Content-type: text/html
.....that bit is totally foriegn to me...hope you can explain for me. Thx very much indeed.
D
in access.conf (or possibly .htaccess?) I point the 404 error code to a script (any old script) in cgi-bin, which will execute each time a 404 occurs...and then in the script (we'll call it 404.pl for now) it will grab the referring page (?) and then we can do something with it...such as the thing with the apache mod_asis (which is the bit that kinda means nothing to me at the moment)....so how/where do I use the bit of code above with:
Status: 200 Now where did I leave that URL
Location: http://xyz.abc.com/foo/bar.html
Content-type: text/html
.....that bit is totally foriegn to me...hope you can explain for me. Thx very much indeed.
D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You could do (in access.conf)
ErrorDocument 404 /cgi-bin/bad_urls.pl
from the apache example which would return a page with the bad url enclosed, or anything else you would like.
Then you could use the apache mod_asis on that returned file to change the response, like this:
Status: 200 Now where did I leave that URL
Location: http://xyz.abc.com/foo/bar.html
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Lame excuses'R'us</TITLE>
</HEAD>
<BODY>
<H1>Fred's exceptionally wonderful page has moved to
<A HREF="http://xyz.abc.com/foo/bar.html">Joe's</A> site.
</H1>
</BODY>
</HTML>
See, you'd put the response you want right in the file, instead of letting Apache stick the response on it.
If you read the apache docs you'll see I shamelessly stole all the above.