Apache mod_rewrite:在 Windows 计算机上使用 PHP 脚本的 RewriteMap 指令
这已经让我发疯了。我似乎无法让 RewriteMap 指令适用于 Windows 上的 php 脚本。以下是我的 httpd.conf 文件中的相关片段:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap router "prg:C:/dev/web/www/routing.php"
RewriteRule (.*) ${router:$1}
</IfModule>
我的简单 php 脚本如下所示:
#!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";
}
?>
当我尝试启动 Apache 时,我在错误日志中收到以下行:
[错误] (OS 193)%1 不是有效的 Win32 应用程序。 :mod_重写: 无法启动 RewriteMap 程序 C:/dev/web/www/routing.php 配置失败
apache 文档 引用了“magic cookie 技巧” (在“外部重写程序”标题下)这应该是脚本的第一行,应该指向解释器。这是我出错的地方还是我需要以不同的方式调用 RewriteMap 指令?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑神奇的 cookie 技巧(也称为 shebang)在 Windows 上是否有效。这是 UNIX/Linux 的一项功能。
您必须指定 PHP 解释器和脚本作为其参数(另请参阅 http:// www.webmasterworld.com/forum92/859.htm):
如果这不起作用,可能是因为
Program Files
中的空间不足。在这种情况下,Windows 支持短名称。例如,PROGRA~1
是一个典型的短名称,但名称中的数字是按照先到先得的原则分配的,因此您应该仔细检查DIR
命令。或者,您可以将
php-win.exe
可执行文件移动到不包含空格的目录。如果还不完全清楚,我会这样说:Windows 很糟糕。
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):
If that doesn't work, it might be because of the space in
Program Files
. Windows supports a short name in such cases. For examplePROGRA~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 theDIR
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.
我有类似的问题。从 CMD 运行 httpd.exe,Apache 应该显示错误。
I had similar problem. Run httpd.exe from CMD, Apache should show error.