Solved

Change response code from 404 to 200

Posted on 2000-05-03
5
349 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:dgb001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:kiffney
ID: 2775269
the ErrorDocument directive in Apache lets you change the default response for any error.

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.
0
 
LVL 1

Author Comment

by:dgb001
ID: 2775290
Looks pretty cool....gimme a while to digest it and I'll get back to you. Thx a lot.

D
0
 
LVL 1

Author Comment

by:dgb001
ID: 2775572
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

0
 
LVL 4

Accepted Solution

by:
kiffney earned 150 total points
ID: 2777065
That bit of code that starts with
Status: 200

IS your response header.  You're doing it yourself instead of letting Apache stick one on for you (that's where you get the default "Status: 404 Not Found" etc.).  That's what the mod_asis lets you do for that response.

As far as writing the script, it can be pretty simple.  If you use perl, you'd just write one that did

print 'Status: 200 ' #etc
print 'Location: ' + $URL #or however perl gives you that environment variable - I don't use perl for web
programming
print
print "<HTML><BODY>" + # all the rest of your page

0
 
LVL 1

Author Comment

by:dgb001
ID: 2777112
Thanks very much....I also found extra info at http://perl.apache.org/faq/

Thx for your time.

D
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question