.htaccess 如何使用RewriteCond测试子目录文件是否存在?

.htaccess 如何使用RewriteCond测试子目录文件是否存在?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,给定输入http://example.com/foo.html如何检查http://example.com/subdir/foo.html存在,使用.htaccess中的mod_rewrite?感觉就像 Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteCond subdir%{REQUEST_URI} -f 应该可以工作,但是当在RewriteCond中使用时,与在RewriteRule中使用时相比,REQUEST\u

给定输入<代码>http://example.com/foo.html如何检查
http://example.com/subdir/foo.html
存在,使用
.htaccess
中的
mod_rewrite
?感觉就像

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond subdir%{REQUEST_URI} -f

应该可以工作,但是当在
RewriteCond
中使用时,与在
RewriteRule

中使用时相比,
REQUEST\u URI
RewriteCond
中使用时(对我而言)会出现意外的行为。您可以这样使用
RewriteCond

# file not present in current directory
RewriteCond %{REQUEST_FILENAME} !-f
# file present in subdir/ directory
RewriteCond %{DOCUMENT_ROOT}/subdir/$0 -f
# rewrite to subdir/ directory
RewriteRule .+ subdir/$0 [L]