限制按文件类型访问目录 [英] Restrict access to a directory by file type
问题描述
我的谷歌福失败了我就这一个...
My Google-fu is failing me on this one...
我试图创造一个Apache的配置,将只允许访问图像,JS和CSS文件在一个特定的目录。
I'm trying to create an Apache config that will only allow access to image, js, and css files in a specific directory.
例如,下面的URL应该工作:
For example, the following URL should work:
mysite.com/dir/image.gif
mysite.com/dir/image.gif
但是这应该被阻止:
mysite.com/dir/page.php
mysite.com/dir/page.php
我是用得到它只是工作/ DIR /苦苦挣扎的一部分。 /目录以外的目录其余/不应该由这个指令会受到影响。
The part I'm struggling with is getting it working only for /dir/. The rest of the directories outside of /dir/ shouldn't be impacted by this directive.
这是我到目前为止,这是不是在做什么,我需要(这似乎适用于所有目录)。
This is what I have so far, which isn't doing what I need (it seems to apply to all directories).
<FilesMatch "\.(gif|jpe?g|jpg|png|js|css)$">
Order deny,allow
Allow from all
</FilesMatch>
我怎么只允许/目录中访问某些文件类型/但不影响我的目录休息吗?
How do I only allow access to certain file types within /dir/ but not affect the rest of my directories?
推荐答案
为了简单起见,我这样做的时候,我通常把所有的媒体文件,在自己的目录中。但是,如果这不是一个选项,您可以尝试FilesMatch指令:
For simplicity, when I do this I usually put all the media files in their own directory. However if this isn't an option you might try the FilesMatch directive:
http://httpd.apache.org/docs/2.2/ MOD / core.html#filesmatch
您可以把FilesMatch的目录里面。
You can put a FilesMatch inside a Directory.
这篇关于限制按文件类型访问目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!