2016-07-27 91 views
1

我有一個網站和.htaccess文件,禁止訪問所有圖像和PDF文件。 我添加了一個新的子文件夾,我需要允許外部訪問這個子文件夾中的圖像和PDF文件。 我該怎麼做?.htaccess允許在一個子文件夾中的圖像

RewriteEngine on 
AuthName "myname" 
AuthUserFile "/home/virtual/website/.htpasswds/public_html/mywebsite/passwd" 
<files ~ "^(admin(.*)\.(php|js))$"> 
require valid-user 
</files> 

RewriteCond %{HTTP_REFERER} !^http://website.com/.*$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://website.com$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com/.*$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com$  [NC] 
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf)$ - [F,NC] 

回答

1

只需要添加另外RewriteCond檢查子文件夾:

RewriteCond ${REQUEST_URI) !^/sub-folder/ [NC] 
RewriteCond %{HTTP_REFERER} !^http://website.com/.*$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://website.com$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com/.*$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com$  [NC] 
RewriteRule \.(jpe?g|gif|png|bmp|pdf)$ - [F,NC] 
1

您應該能夠添加一個條件,以排除子文件夾

RewriteCond %{HTTP_REFERER} !^http://website.com/.*$ [NC] 
RewriteCond %{HTTP_REFERER} !^http://website.com$ [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com/.*$ [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.website.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/subfolder [NC] 
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf)$ - [F,NC] 
+0

這兩個答案張貼在完全相同的第二:)但這將解除阻止'/ subfolder123.pdf'文件 – anubhava

+0

謝謝! @anubhava - 沒關係,我沒有這個名字的文件:) – TamarG

相關問題