Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 即使存在相同URL的文件,也要执行重写(不会出现错误500:无限递归)_.htaccess_Rewrite - Fatal编程技术网

.htaccess 即使存在相同URL的文件,也要执行重写(不会出现错误500:无限递归)

.htaccess 即使存在相同URL的文件,也要执行重写(不会出现错误500:无限递归),.htaccess,rewrite,.htaccess,Rewrite,我正在尝试在.htaccess文件中进行重写,即使文件与请求的URL位于同一位置 i、 e.我希望重写/about/index.html,即使/about/index.html上有一个文件 目前我有: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^thehost.example.com$ RewriteCond %{REQUEST_URI} !^/dont-rewrite-when-at-this-url RewriteRule

我正在尝试在.htaccess文件中进行重写,即使文件与请求的URL位于同一位置

i、 e.我希望重写/about/index.html,即使/about/index.html上有一个文件

目前我有:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^thehost.example.com$
RewriteCond %{REQUEST_URI} !^/dont-rewrite-when-at-this-url
RewriteRule ^(.*)(/|\.html|\.txt)$ /path/to/stubfile.html?/$1$2 [last,qsappend]
问题是如果我要求

并且存在一个位于/about/index.html的文件,这就是我想要的,也就是说,如果该文件确实存在,则应该进行重写,但如果该文件不存在,则也可以进行重写

然后我得到错误500:无限递归

添加一个RewriteCond来豁免正在重写的stubfile本身并没有什么区别

表明缺少a-f RewriteCond会阻止递归,但这会导致我不希望发生的行为


是否有办法进行重写,即忽略文件存在的事实,即使存在相同URL的文件,也只需重写?

只需排除您重定向到的目标,在本例中为/path/to/stubfile.html:


不;正如我所说,添加RewriteCond以免除stubfile本身仍然会导致递归。谢谢你的建议。@fooquency:What是/path/to/stubfile.html?URL路径或文件系统路径?只是澄清一下-这是一个内部无限递归错误,导致浏览器中出现可见的500错误-而不是由浏览器报告的重定向循环。
RewriteCond %{HTTP_HOST} ^thehost.example.com$
RewriteCond %{REQUEST_URI} !^/dont-rewrite-when-at-this-url
RewriteCond %{REQUEST_URI} !=/path/to/stubfile.html
RewriteRule ^(.*)(/|\.html|\.txt)$ /path/to/stubfile.html?/$1$2 [last,qsappend]