我如何限制对我的文件夹的访问

发布于 2024-10-29 20:59:42 字数 781 浏览 1 评论 0原文

我正在使用 codeigniter 构建一个包含大量图像库的网站,我将图像存储在文件夹中,但我想通过 url 限制对文件夹的访问。即我不希望人们使用 url 访问我的图像文件夹像这样::

http://website/all_images/

所有图像是包含图像文件夹的文件夹..我尝试过使用 htaccess 文件,

 <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteCond %{REQUEST_URI} ^CI_system.*
     RewriteRule ^(.*)$ /website/index.php?/$1 [L]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond $1 !^(index\.php|all_images)
     RewriteRule ^(.*)$ /website/index.php?/$1 [L]
 </IfModule>
 <IfModule !mod_rewrite.c>

  ErrorDocument 404 /index.php
  </IfModule>

index.php 的重写条件效果很好,但我仍然可以通过 url 访问我的所有文件夹

am using codeigniter to build a website with a lot of image galleries , i store the images in folders ,but i want to restrict access to the folders via url .i.e i don't want people to have access to my image folder using a url like this::

http://website/all_images/

all images is the folder that contains the image folder .. i tried using a htaccess file

 <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteCond %{REQUEST_URI} ^CI_system.*
     RewriteRule ^(.*)$ /website/index.php?/$1 [L]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond $1 !^(index\.php|all_images)
     RewriteRule ^(.*)$ /website/index.php?/$1 [L]
 </IfModule>
 <IfModule !mod_rewrite.c>

  ErrorDocument 404 /index.php
  </IfModule>

the rewrite condition for the index.php works well but i still get access to all my folders via the url

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生共白头 2024-11-05 20:59:42

如果您想禁止查看文件夹,只需添加空的index.html文件,但如果您尝试保护图像不被查看,那么您的网站也将无法找到它们

If you want to disable folders to be viewed, just add empty index.html file, but if you try to protect images from being viewed then your website wont be able to find them too

无可置疑 2024-11-05 20:59:42

为什么不在该文件夹下创建一个索引文件。这样,任何人都将无法查看该文件夹下的图像。

您可以使该文件调用一个显示“访问被拒绝”或您需要的任何内容的函数。

Why don't you create an index file under that folder. In this way no will will be able to view images under that folder.

You can make this file call a function that says "access denied" or whatever you need.

烟花易冷人易散 2024-11-05 20:59:42

选项 - htaccess 文件中的索引将停止目录查看,无需额外文件。如果您想停止直接查看图像,即 myweb.com/all_images/coolpic.jpg 那么您所要做的就是(因为您的基础是/您可以使用下面的整个内容):

Options -Indexes
ErrorDocument 404 /index.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  RewriteCond %{HTTP_REFERER} !^$ 
  RewriteCond %{HTTP_REFERER} !^http://(www\.)?myweb.com/.*$ [NC] 
  RewriteRule \.(gif|jpg)$ - [F]
</IfModule>

您需要更改的只是该行包含您的网址,并将所有文件类型添加到最后的重写规则中(用管道 | 分隔每个文件类型),然后这将 100% 覆盖您讨论过的所有角度。

Options -Indexes in your htaccess file will stop directory viewing no extra files needed. and if you want to stop direct image viewing i.e. myweb.com/all_images/coolpic.jpg then all you have to do is (since your base is / you can use the whole one below):

Options -Indexes
ErrorDocument 404 /index.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  RewriteCond %{HTTP_REFERER} !^$ 
  RewriteCond %{HTTP_REFERER} !^http://(www\.)?myweb.com/.*$ [NC] 
  RewriteRule \.(gif|jpg)$ - [F]
</IfModule>

All you would have to change is the line with your web address in it and add all of your file types to the last rewrite rule (seperating each with a pipe |) and then this will cover all of the angles you have discussed 100%.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文