Apache mod_rewrite:在 Windows 计算机上使用 PHP 脚本的 RewriteMap 指令

发布于 2024-09-15 03:31:43 字数 958 浏览 2 评论 0原文

这已经让我发疯了。我似乎无法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你只要分分秒秒 2024-09-22 03:31:43

我怀疑神奇的 cookie 技巧(也称为 shebang)在 Windows 上是否有效。这是 UNIX/Linux 的一项功能。

您必须指定 PHP 解释器和脚本作为其参数(另请参阅 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"

如果这不起作用,可能是因为 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):

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.

野の 2024-09-22 03:31:43

我有类似的问题。从 CMD 运行 httpd.exe,Apache 应该显示错误。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文