2011-04-01 112 views
1

上午使用codeigniter來建立一個網站,有很多圖片庫,我將圖片存儲在文件夾中,但我想限制通過URL訪問文件夾.ie我不'不想人在使用這樣的網址::我如何限制訪問我的文件夾

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 w的重寫條件orks很好,但我仍然可以通過url訪問我所有的文件夾

回答

1

爲什麼不在該文件夾下創建索引文件。通過這種方式,沒有人會在該文件夾下查看圖像。

你可以使這個文件調用一個函數,說「拒絕訪問」或任何你需要的。

+0

@BrandonS和@luci tnks很多 – 2011-04-13 15:23:21

3

如果您希望禁用要查看的文件夾,只需添加空的index.html文件,但如果你試圖保護圖像被視爲那麼你的網站將無法找到他們太

0

選項-Indexes在你的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%。