[thelist] Apache Redirect Question

Mark Groen evolt at markgroen.com
Wed Sep 21 21:50:29 CDT 2005


----- Original Message ----- 
From: "Dan Romanchik" <>
To: <thelist at lists.evolt.org>
Sent: Wednesday, September 21, 2005 1:05 PM
Subject: [thelist] Apache Redirect Question


> I maintain a website that requires payment for access to
> certain content. That content is in a particular
> subdirectory. I am using IP authentication for that
> particular subdirectory, and that's working quite well. If
> someone tries accessing files in that subdirectory from an
> IP address that's not allowed, a 403 status gets returned,
> and I redirect the user to a file in the root directory.
>
> My question is how I can return a 200 or 30X status when the
> server serves up the redirect file. Is this possible?

Apache is going to serve up the file it supposed to, in this case it's a
403 so...

in your htaccess, send the 403 to a different place:

errordocument 403 /someotherfile.php

and then in the someotherfile.php, use php to fake out the headers and
call the page a 204 code for "no content" or something like that. You
can replace some of the lines in the header info with php header()
function:

HTTP/1.1 200 OK
Date: Thu, 31 Jul 2003 21:35:46 GMT
Server: Apache/1.3.26 (Unix) mod_perl/1.27
Cache-Control: max-age=0
Expires: Thu, 31 Jul 2003 21:35:46 GMT
Connection: close
Content-Type: text/html

So - this should get you there, (http_response_code):
http://ca3.php.net/manual/en/function.header.php

For those that love SSI instead of PHP for this sort of work, here's a
tutorial that's also got a lot of extra good information about Apache
error handling, and how it can be used to make your site more accessible
and user-friendly:
http://www.php-editors.com/apache_manual/misc/custom_errordocs.html

hth!

cheers,

        Mark



More information about the thelist mailing list