mod_rewrite:重写URL以指向cgi脚本,但保持重写隐藏

时间:2022-06-09 08:22:26

I'm trying to rewrite the URL

我正在尝试重写网址

http://domain.com/whatever 

To:

http://domain.com/cgi-bin/script.cgi

My .htaccess file looks like this:

我的.htaccess文件如下所示:

RewriteEngine On
RewriteRule /whatever /cgi-bin/script.cgi [NC]

This doesn't work and gives me a 404 error. However, this works:

这不起作用,并给我404错误。但是,这有效:

RewriteEngine On
RewriteRule /whatever http://domain.com/cgi-bin/script.cgi [NC]

But in that case, the URL change is vivible to the user. What am I doing wrong?

但在这种情况下,URL更改对用户是可行的。我究竟做错了什么?

1 个解决方案

#1


Adding the [PT] flag fixed it:

添加[PT]标志修复它:

RewriteEngine On
RewriteRule /whatever /cgi-bin/script.cgi [NC,PT]

Now if somebody could just explain why that's needed and what is actually going on, I would be extremely grateful.

现在,如果有人能够解释为什么需要这样做以及实际发生了什么,我将非常感激。

#1


Adding the [PT] flag fixed it:

添加[PT]标志修复它:

RewriteEngine On
RewriteRule /whatever /cgi-bin/script.cgi [NC,PT]

Now if somebody could just explain why that's needed and what is actually going on, I would be extremely grateful.

现在,如果有人能够解释为什么需要这样做以及实际发生了什么,我将非常感激。