Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Changing http headers in cgi response

by twotone (Beadle)
on Sep 10, 2010 at 05:16 UTC ( #859592=note: print w/replies, xml ) Need Help??

in reply to Re: Changing http headers in cgi response
in thread Changing http headers in cgi response

Hmmm... It seems I wasn't clear enough in my question. I'm not trying to return Status 202 OK when the content isn't found. I'm just not wanting to create (let's say 50) identical cgi scripts for the 50 "virtual" pages I have in my database. I want to display any of those 50 pages by using only 1 script. The page would be chosen based on the URL content after the domain like this: So that when that page content is FOUND in the database, the content is returned with status 202.

This would be a the process step by step:

  • Page is requested:
  • My script is registered as custom 404 handler
  • script does database query for requested/page/
  • if found, requested/page/ is returned with 202 OK
  • if not, 404 not found is returned
I set up a drupal site once on a server that didn't do url rewriting and this was exactly the way drupal did it. I just don't remember if it modified the 404 status to 202.

SO, can any one tell me how to change the 404 status header to 202 when I send back the found page?

  • Comment on Re^2: Changing http headers in cgi response

Replies are listed 'Best First'.
Re^3: Changing http headers in cgi response
by Your Mother (Bishop) on Sep 10, 2010 at 06:24 UTC

    I think you might be unclear what 202 means(?). It's not for "content" at all. It's for saying, "I got your request and I'll look into it and let you know; maybe here's a link or something you so you can check back when I'm ready with what you actually asked for."

    You are trying to overload your web server to behave as your dispatcher. Don't do it. Use proper dispatch and server configuration. Here is an example (untested—pasted from a web sample—and might need correction) configuration for apache to point to a script (fastcgi in this case but CGI should work too)-

    RewriteEngine On RewriteRule ^(/somedir/dispatch\.fcgi/.*)$ - [L] RewriteRule ^(.*)$ somedir/dispatch.fcgi/$1 [PT,L]

    Then you can use the request URI (everything in the path after the script's name) inside your (F)CGI to do the things you're talking about wanting to do while returning proper status codes to match.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://859592]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-10-20 14:32 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (210 votes). Check out past polls.