httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Trutwin <j...@trutwins.homeip.net>
Subject [users@httpd] PhP Rewrite Map File Problem
Date Fri, 30 Nov 2007 21:00:17 GMT
Hi - through some great help from this list (I'm looking at you
Joshua Slive) I was able to setup a RewriteMap using a PhP program.
After a couple months usage on a number of heavy sites we're noticing
an odd inconsistent problem that causes ALL site requests to yeild
this nasty error:

mod_rewrite: maximum number of internal redirects reached. Assuming
configuration error. Use 'RewriteOptions MaxRedirects' to increase
the limit if neccessary.

The program is called rewriter.php and starts with this directive:

RewriteLock '/tmp/rewrite.lock'
RewriteMap rewriter prg:/usr/local/bin/rewriter.php

A site that wants to use this URL mapper has this in their .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* ${rewriter:%{REQUEST_FILENAME}^%{REQUEST_URI}}
[L,QSA,NS]

There are some other directives involved to 301 redirect old URL's
to the new ones, but I don't think they are the problem.

The program source can be seen here:

http://batcave.intrcomm.net/rewriter.phps

In a nutshell what happens is the program parses stdin (which from
the RewriteRule is the REQUEST_FILENAME followed by the REQUEST_URI)
- from this information it can find the site's virtual host directory
and load a file called _rewrite_map.php which is a simple php
associated array containing for each page then URL should it map
to. This works fine until someone updates that file through releasing
pages on their site (via a CMS).  Occasionally, (maybe 5% of the
time) when this file is updated the above error occurs on every
request.  The ONLY way to fix this is to hard stop and start the
server (a restart doesn't restart the php RewriteMap program)  When
the server is restarted, all works well - until the next time
updating this file causes this problem.

I've added some logging where the URL is returned to the apache
process:

if (DEBUG) { error_log("Map found for URI: $uri: $uri_under " .
$map[$uri] . "\n", 3, '/tmp/rewriter.log'); }

fputs($stdout, $map[$uri] . "\n"); // tell RewriteRule the URL

Even when these maximum redirect errors are happening, the program is
still logging the above using the correct URL - it's not having any
problems accessing the map file.  I added some additional file locking
(also to the program that updates the file) but that didn't help.

Someone at work here suggested that it might have to do with how
stdin and stdout are defined, which makes sense so I'm trying that
next but I wanted to see if any gurus on this list know of any
strange RewriteMap bugs/gotchas like this.

PhP is 4.4 - apache is 1.3.37 - linux 2.4

Thanks - let me know if additional info is needed.

Josh




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message