如何阻止直接访问我的JavaScript文件? [英] How can I block direct access to my JavaScript files?
问题描述
我使用Minify来缩小和缓存我的所有脚本请求。 我只希望我的用户能够访问缩小版本的JavaScript文件。
I use Minify to minify and cache all my script requests. I only want my users to be able to access the minified versions of the JavaScript files.
缩小谎言 www .example.com / min
我的脚本位于 www.example.com/scripts
。如何阻止直接访问 doc_root / scripts
,这是我未明确的JavaScript文件所在的位置。我宁愿不把它们从文档根目录中删除,但它是一个选项。
Minify lies at www.example.com/min
and my scripts are at www.example.com/scripts
. How can I block direct access to doc_root/scripts
which is where my unminified JavaScript files lie. I'd rather not put them out of the document root but it's an option.
请注意我使用的是Zend Framework,所以我的应用程序的实际根目录是转移到 www.example.com/public
。 htaccess文件处理重写。
Please note that I'm using Zend Framework, so the actual root of my application is shifted to www.example.com/public
. An htaccess file handles the rewrite.
推荐答案
你不能只在 doc_root中使用.htaccess文件/ scripts
阻止通过HTTP访问网络上的所有 .js
文件?
Can't you just use an .htaccess file inside doc_root/scripts
to prevent all access over the web to .js
files over HTTP?
它不会停止缩小,因为它提供间接访问。
It won't stop minify, since that provides indirect access.
所以在 doc_root / scripts / .htaccess
,类似于
<Files ~ "\.js$">
order allow,deny
deny from all
</Files>
请注意 .htaccess
的位置在这种情况下,文件很重要。
Note that the location of the .htaccess
file matters in this case.
这篇关于如何阻止直接访问我的JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!