Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
Regex %{REQUEST_URI}是否总是以斜杠开头?_Regex_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Regex %{REQUEST_URI}是否总是以斜杠开头?

Regex %{REQUEST_URI}是否总是以斜杠开头?,regex,apache,.htaccess,mod-rewrite,url-rewriting,Regex,Apache,.htaccess,Mod Rewrite,Url Rewriting,我已经在2-3台apache服务器上执行了测试,如果我的头脑没有背叛我,%{REQUEST\u URI}总是以/开头,即使请求的URL是(没有斜杠和结尾)。但是我见过.htaccess文件有如下规则: RewriteRule ^[^/]*$ http... 我的意思是,这种规则会匹配{REQUEST\u URI}?或者我可能遗漏了一些关于mod_rewrite的内容(在RewriteRule之后的参数是否与%{REQUEST_URI}相同,因此不会发生匹配?) 如果有人能告诉我这一点,我将不胜

我已经在2-3台apache服务器上执行了测试,如果我的头脑没有背叛我,
%{REQUEST\u URI}
总是以
/
开头,即使请求的URL是(没有斜杠和结尾)。但是我见过.htaccess文件有如下规则:

RewriteRule ^[^/]*$ http...
我的意思是,这种规则会匹配
{REQUEST\u URI}
?或者我可能遗漏了一些关于mod_rewrite的内容(在
RewriteRule
之后的参数是否与
%{REQUEST_URI}
相同,因此不会发生匹配?)


如果有人能告诉我这一点,我将不胜感激。

重写规则
模式不一定与
%{REQUEST\u URI}
匹配。发件人:

什么是匹配的? 在上下文中,模式最初将被匹配 针对URL中主机名和端口之后以及之前的部分 查询字符串(例如“/app1/index.html”)

在和htaccess上下文中,模式最初是 删除前缀后,与文件系统路径匹配 将服务器引导到当前的重写规则(例如“app1/index.html”或 “index.html”,具体取决于指令的定义位置)


因为您在
htaccess
文件中看到了这些,所以要匹配的路径将不会以
/
开头,因为删除的前缀将至少包含一个
/
。htaccess
是根据目录指令的,Apache会删除当前目录路径(因此,如果放在DocumentRoot中,则前导斜杠)从
RewriteRule
URI模式

另一方面,
%{REQUEST_URI}
始终包含从域名后的
/
开始的完整URI值

通过以下URL示例可以清楚地看到:

URL: http://domain.com/path/files/user.php
案例1:
.htaccess
位于
文档根目录中:

%{REQUEST_URI}: /path/files/user.php
RewriteRule pattern: path/files/user.php
案例2:
.htaccess
位于
DocumentRoot/path/
中:

%{REQUEST_URI}: /path/files/user.php
RewriteRule pattern: files/user.php
案例3:
.htaccess
位于
DocumentRoot/path/files/
中:

%{REQUEST_URI}: /path/files/user.php
RewriteRule pattern: user.php