Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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_filename})更改为.htaccess中的新路径_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 将请求文件名(%{request_filename})更改为.htaccess中的新路径

Regex 将请求文件名(%{request_filename})更改为.htaccess中的新路径,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我试图在.htaccess中使用重写规则,与别名/var/www/html/core/Alias/var/www/html/core/latest/相同 我在/var/www/html/core中制作了这个.htaccess: RewriteEngine On #Check if file exist in original path (/var/www/html/core): RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQU

我试图在.htaccess中使用
重写规则
,与
别名/var/www/html/core/Alias/var/www/html/core/latest/
相同

我在/var/www/html/core中制作了这个.htaccess

RewriteEngine On

#Check if file exist in original path (/var/www/html/core):
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

#try new path (/var/www/html/core/latest):
RewriteRule ^(.*)$ latest/$1 [NC,L]
这很有效。但如果文件在/var/www/html/core/latestapache中不存在,则显示内部服务器错误,而不是正常的404错误。因此,我必须在最后一个
重写规则
之前使用一些
RewriteCond***-f
,以确保文件存在于新路径中

问题是我无法将
%{REQUEST\u FILENAME}
更改为
最新的/%{REQUEST\u FILENAME}
。例如:

core/img/loading.gif必须签入core/latest/img/loading.gif,而不是latest/core/img/loading.gif


是否可以以某种方式在.htaccess中解析
%{REQUEST_FILENAME}

您可以像这样调整规则:

RewriteEngine On
RewriteBase /core/

#Check if file exist in original path (/var/www/html/core):
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

#try new path (/var/www/html/core/latest):
RewriteCond %{DOCUMENT_ROOT}/core/latest/$1 -f
RewriteRule ^((?!latest/).*)$ latest/$1 [L,NC]

RewriteCond%{DOCUMENT\u ROOT}/core/latest/$1-f
确保文件存在于
/core/latest/
文件夹中

您是否同时使用mod alias和mod rewrite?是的,首先在apache的配置中使用
AliasMatch^/core/?(.*)/var/www/html/core/$1
。然后将.htaccess放在核心目录中。