mod_rewrite的,我想如果一个文件在另一个目录中存在检测和检索 [英] mod_rewrite, I want to detect if a file exists in another directory and retrieve that
本文介绍了mod_rewrite的,我想如果一个文件在另一个目录中存在检测和检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要指向一个子目录的文件,如果它的存在。
I want to point to a sub directory file if it exists.
目前我已经在Web根目录.htaccess文件:
Currently I have in an .htaccess file at the webroot:
RewriteCond my_sub_dir/%{REQUEST_FILENAME} -d
RewriteRule ^.*$ my_sub_dir/%{REQUEST_FILENAME} [L]
基本上我想要 http://example.com/js/application.js 点到my_sub_dir / JS / application.js中如果存在
Basically I want http://example.com/js/application.js to point to my_sub_dir/js/application.js if it exists
推荐答案
-d
测试给出的路径是现有目录的有效路径。如果你想测试常规文件,使用 -f
来代替。但你也需要提供一个绝对的文件系统路径。所以,试试这个:
-d
tests if the given path is a valid path to an existing directory. If you want to test for regular files, use -f
instead. 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]
这篇关于mod_rewrite的,我想如果一个文件在另一个目录中存在检测和检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文