Apache mod_rewrite: RewriteMap directive using PHP script on Windows machine
Asked Answered
A

2

6

This has been driving me insane. I can't seem to get the RewriteMap directive to work for a php script on windows. Here is the relevant snippet from my httpd.conf file:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteMap router "prg:C:/dev/web/www/routing.php"
        RewriteRule (.*) ${router:$1}
</IfModule>

My simple php script reads like this:

#!C:\Program Files\PHP5.3.2\php-win.exe
<?php

set_time_limit(0); # forever program!
$keyboard = fopen("php://stdin","r");
while (1) {
        $line = trim(fgets($keyboard));
        echo "/sandbox.php?url=$line";
        echo "\n";
}
?>

When I attempt to start Apache I get the following line in my error log:

[error] (OS 193)%1 is not a valid Win32 application. : mod_rewrite: could not start RewriteMap program C:/dev/web/www/routing.php Configuration Failed

The apache documentation refers to the 'magic cookie trick' (under the 'External Rewriting Program' heading) which should be the first line of the script which should point to the interpreter. Is this where I'm going wrong or do I need to call the RewriteMap directive differently?

Althorn answered 18/8, 2010 at 20:1 Comment(0)
C
6

I doubt the magic cookie trick, also known as the shebang, would work on Windows. This is a UNIX/Linux feature.

You'll have to specify the PHP interpreter and the script as its argument (see also http://www.webmasterworld.com/forum92/859.htm):

RewriteMap router "prg:C:/Program Files/PHP5.3.2/php-win.exe C:/dev/web/www/routing.php"

If that doesn't work, it might be because of the space in Program Files. Windows supports a short name in such cases. For example PROGRA~1 is a typical short name, but the digit in the name is assigned on a first-come first served basis, so you should double-check with the DIR command.

Or else you could move your php-win.exe executable to a directory that doesn't contain spaces.

If it isn't totally clear already, I'll say this: Windows sucks.

Conscionable answered 18/8, 2010 at 20:24 Comment(2)
(+1) Comments in apr_proc_create (used to invoke the program) also make note: progname must be unquoted, in native format, as there are all sorts of bugs in the NT library loader code that fault when parsing '/', though I'm not sure how much of an issue it actually is. It looks like the command gets auto-quoted later (as necessary) too, so hopefully the spaces shouldn't be an issue.Agonist
@Tim: Thanks! Anyway, the spaces are something to be mindful of because they can bite you in various circumstances.Conscionable
A
0

I had similar problem. Run httpd.exe from CMD, Apache should show error.

Apophasis answered 16/4, 2011 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.