Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_rewrite:重写URL以指向cgi脚本,但保持重写隐藏_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

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

Apache mod_rewrite:重写URL以指向cgi脚本,但保持重写隐藏,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正试图重写URL http://domain.com/whatever 致: 我的.htaccess文件如下所示: RewriteEngine On RewriteRule /whatever /cgi-bin/script.cgi [NC] 这不起作用,给我一个404错误。然而,这是可行的: RewriteEngine On RewriteRule /whatever http://domain.com/cgi-bin/script.cgi [NC] 但在这种情况下,URL更改对用户

我正试图重写URL

http://domain.com/whatever 
致:

我的.htaccess文件如下所示:

RewriteEngine On
RewriteRule /whatever /cgi-bin/script.cgi [NC]
这不起作用,给我一个404错误。然而,这是可行的:

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

但在这种情况下,URL更改对用户来说是灵活的。我做错了什么?

添加
[PT]
标记修复了它:

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

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

我使用apache重写引擎时遇到了与非PHP CGI相同的问题。 一切正常,但未添加查询字符串

要解决这个问题,您必须在重写配置中设置“QSA”参数

DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Multiviews Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all

#
# Controls who can get stuff from this server.
#
AddHandler cgi-script .vbs .wsf .rex .bat .cmd .bas .rexg
#   onlineoffline tag - don't remove

#Require local

RewriteEngine   on

#RewriteRule "(.*\.vbs)$" "/cgi/test.rex"
#[H=cgi-script]
# AVOID RECURSION BY CONDITION !!!
RewriteCond  "%{REQUEST_FILENAME}" "!(.*)/cgi\.rex" 
RewriteRule "(.*\.rex)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]
RewriteRule "(.*\.vbs)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]
RewriteRule "(.*\.rsp)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]



#RewriteLog      "/var/log/apache2/rewrite.log"
#RewriteLogLevel 2



</Directory>
DocumentRoot“${INSTALL\u DIR}/www”
#
#选项指令的可能值为“无”、“全部”,
#或以下任何组合:
#索引包括以下符号链接符号链接所有者匹配执行CGI多视图
#
#请注意,“多视图”必须显式命名为*--“所有选项”
#不给你。
#
#期权指令既复杂又重要。请看
# http://httpd.apache.org/docs/2.4/mod/core.html#options
#了解更多信息。
#
选项索引如下SYMLINKS多视图包括ExecCGI
#
#AllowOverride控制可在.htaccess文件中放置的指令。
#它可以是“全部”、“无”或关键字的任意组合:
#AllowOverride文件信息AuthConfig限制
#
允许超越所有
#
#控制谁可以从此服务器获取内容。
#
AddHandler cgi script.vbs.wsf.rex.bat.cmd.bas.rexg
#onlineoffline标记-不删除
#要求本地
重新启动发动机
#重写规则“(.\.vbs)$”/cgi/test.rex”
#[H=cgi脚本]
#避免条件递归!!!
重写条件“%{REQUEST_FILENAME}”“!(.*)/cgi\.rex”
重写规则“(.\.rex)$”/cgi/cgi.rex?$1”[NC、PT、QSA]
重写规则“(.\.vbs)$”/cgi/cgi.rex?$1”[NC、PT、QSA]
重写规则“(.\.rsp)$”/cgi/cgi.rex?$1”[NC、PT、QSA]
#RewriteLog“/var/log/apache2/rewrite.log”
#重写日志级别2

更改后,查询字符串环境恢复:)

是否有其他规则?此外,重写规则的模式没有前导斜杠(用于匹配的URI删除了前导斜杠),没有其他规则。这些是.htaccess文件的完整内容。我不知道你说的前导slahes是什么意思,但第二个示例可以执行重定向,所以我不认为这是模式的问题……编辑:没关系,我错了。
passthrough | PT
-强制将生成的URI传递回URL映射引擎,以便处理其他URI到文件名转换器,例如别名或重定向。默认情况下,重写规则中的目标(或替换字符串)假定为文件路径。[PT]标志的使用导致它被视为URI。也就是说,使用[PT]标志会导致重写规则的结果通过URL映射传回,因此基于位置的映射(例如Alias、Redirect或ScriptAlias)可能有机会生效。例如,如果您有/icons的别名,并且有一个RewriteRule指向此处,则应使用[PT]标记以确保对别名进行求值。在这种情况下,省略[PT]标志将导致忽略别名,导致返回“未找到文件”错误。因此,您可能有一些重定向或别名本应应用于重写的URL?
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Multiviews Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all

#
# Controls who can get stuff from this server.
#
AddHandler cgi-script .vbs .wsf .rex .bat .cmd .bas .rexg
#   onlineoffline tag - don't remove

#Require local

RewriteEngine   on

#RewriteRule "(.*\.vbs)$" "/cgi/test.rex"
#[H=cgi-script]
# AVOID RECURSION BY CONDITION !!!
RewriteCond  "%{REQUEST_FILENAME}" "!(.*)/cgi\.rex" 
RewriteRule "(.*\.rex)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]
RewriteRule "(.*\.vbs)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]
RewriteRule "(.*\.rsp)$" "/cgi/cgi.rex?$1" [NC,PT,QSA]



#RewriteLog      "/var/log/apache2/rewrite.log"
#RewriteLogLevel 2



</Directory>