简体   繁体   English

mod_rewrite,我要检测另一个目录中是否存在文件并检索该文件

[英]mod_rewrite, I want to detect if a file exists in another directory and retrieve that

I want to point to a sub directory file if it exists. 我要指向子目录文件(如果存在)。

Currently I have in an .htaccess file at the webroot: 目前,我在webroot中有一个.htaccess文件:

RewriteCond my_sub_dir/%{REQUEST_FILENAME} -d
RewriteRule ^.*$ my_sub_dir/%{REQUEST_FILENAME} [L]

Basically I want http://example.com/js/application.js to point to my_sub_dir/js/application.js if it exists 基本上,我希望http://example.com/js/application.js指向my_sub_dir / js / application.js(如果存在)

-d tests if the given path is a valid path to an existing directory. -d测试给定路径是否为现有目录的有效路径。 If you want to test for regular files, use -f instead. 如果要测试常规文件,请改用-f But you also need to provide an absolute filesystem path. 但是您还需要提供一个绝对的文件系统路径。 So try this: 所以试试这个:

RewriteCond %{DOCUMENT_ROOT}/my_sub_dir%{REQUEST_URI} -f
RewriteRule ^ %{DOCUMENT_ROOT}/my_sub_dir%{REQUEST_URI} [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM