1

I am on a Network Solutions VPS, four domain names share the IP. I have a Rewrite / RewriteMap set up that works. The Rewrite is in the file for the example.com web address at var/www/vhosts/example.com/conf/vhost.conf, the Rewrite being the only thing in the vhost.conf file. It would not work in the main httpd.conf file for the server.

The RewriteMap uses a couple things in the URL typed in by the user (http://example.com/bb/cc) to get a third piece of info (aa) from the matching database record, uses that third piece of info as the query string to load a file, and leaves the originally typed in URL in the address bar while showing the file based on the query string aa.

Here is the Rewrite:

Options +FollowSymlinks
RewriteEngine on
RewriteMap newurl "prg://var/www/cgi-bin/examplemap.php"
RewriteRule ^/(Example/.*) ${newurl:$1} [L]

When I add the following either above or below the RewriteMap line:

RewriteLock /var/lock/mapexamplelock

and try to re-start Apache, it hangs and Apache will not re-start. I have tried different file paths (thinking it might be a permissions issue and just hoping it worked of course), taking away the initial /, putting it in quotes, different file types (ie. .txt at the end), different file names, just about anything, and every time it hangs Apache on re-start. The Rewrite / RewriteMap works without it, but I have read a lot on the importance of the RewriteLock, and php is issuing warnings in the log ending in DANGEROUS not to use RewriteLock.

Here is the map (located where the Rewrite says):

#!/usr/bin/php
<?php
include '/pathtodatabase';
set_time_limit(0);
$keyboard = fopen("php://stdin","r");
while (1) {
$line = fgets($keyboard);
if (preg_match('/(.*)\/(.*)/', $line, $igot)) {
$getalias = mysql_query("select aa FROM `table`.`dbase` WHERE bb = '$igot[1]' && cc =     '$igot[2]'");
while($row=mysql_fetch_array($getalias)) {
$arid = $row['aa'];
}
print "/file-to-take-load.php?aa=$arid\n";
}
else {
print "$line\n";
}
}
?>

I looked in the main httpd.conf file and there is nothing I can find about RewriteLock that might be interfering. It's just the standard one that came in the set-up of the VPS.

If anyone has an idea about why this would work only without RewriteLock and the possible fix, it would be greatly appreciated.

Thanks Greg

kidcobra
  • 23
  • 3
  • What do you mean, "it crashes Apache". What error does it produce? – larsks Jun 04 '12 at 15:31
  • Hi. After putting in that line of code, Apache will not re-start and just hangs, so the website is down until I remove that line of code and re-start of Apache without that the Lock line. – kidcobra Jun 04 '12 at 15:40
  • And again, what errors does it produce? Apache seldom crashes without something showing up in the error log. – larsks Jun 04 '12 at 15:40
  • Hi. There is no error in my regular error log. It just won't restart. – kidcobra Jun 04 '12 at 15:43
  • Hi. I edited the question to more fully explain that Apache won't restart and hangs. The changes to the conf file aren't recognized until I restart Apache, but in this case, it won't start-up with the RewriteLock line of code in there. – kidcobra Jun 04 '12 at 15:48
  • @kidcobra - Please see a similar question I opened at http://stackoverflow.com/questions/16386974/apache-rewritelock-alternative-using-php. Have you gone down the same road I am by chance? – Inator May 06 '13 at 21:04

1 Answers1

4

Apache hangs if you define more than one RewriteLock directives or if you use it in a VHOST config.

The RewriteLock should be specified at server config level and ONLY ONCE. This lock file will be used by all prg type maps. So if you want to use multiple prg maps, I suggest using an internal locking mechanism, for example in PHP there is the flock function, and simply ignore the warning apache writes in the error log.

See here for more info:
http://books.google.com/books?id=HUpTYMf8-aEC&lpg=PP1&pg=PA298#v=onepage&q&f=false

D. Marti
  • 365
  • 2
  • 4
  • Please see my question at http://stackoverflow.com/questions/16386974/apache-rewritelock-alternative-using-php. Is my approach a correct way of doing what you describe? – Inator May 06 '13 at 21:01