Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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 存在文件时Apache重定向不起作用_Regex_Apache_Redirect - Fatal编程技术网

Regex 存在文件时Apache重定向不起作用

Regex 存在文件时Apache重定向不起作用,regex,apache,redirect,Regex,Apache,Redirect,我正在使用以下正则表达式: ^/(.*)/(?i:audaud)(.*)$ 这是可行的,重定向任何“aud”或“aud”等到我想要的页面。当我尝试访问位于/catalog/aud.html的文件时,问题出现了。每当我这样做,我就会得到一个404 有人知道为什么会发生这种情况吗?一种解决方案是添加一个负面的前瞻以排除该文件: ^/(.*)/(?!AUDAUD\.html$)(?i:audaud)(.*)$ 负前瞻(?!AUDAUD\.html$)断言下面的内容不是AUDAUD.html$和字符

我正在使用以下正则表达式:

^/(.*)/(?i:audaud)(.*)$
这是可行的,重定向任何“aud”或“aud”等到我想要的页面。当我尝试访问位于/catalog/aud.html的文件时,问题出现了。每当我这样做,我就会得到一个404


有人知道为什么会发生这种情况吗?

一种解决方案是添加一个负面的前瞻以排除该文件:

^/(.*)/(?!AUDAUD\.html$)(?i:audaud)(.*)$
负前瞻
(?!AUDAUD\.html$)
断言下面的内容不是
AUDAUD.html$
和字符串的结尾

另一种选择是在正则表达式的开头将整个路径包含在负前瞻中:

^(?!/catalog/AUDAUD\.html$)/(.*)/(?i:audaud)(.*)$

这是一个快速解决方案,但如果您想要更精确的调整(我确信可以提供,请显示整个重定向)。似乎我编写的一个旧的mod_重写规则直接指向一个php在我的mod_别名之前拦截了请求。这就解释了它奇怪的行为。