簡體   English   中英

除非來自指定文件,否則如何阻止對文件或目錄的請求?

[英]How can I block requests for a file or directory unless it comes from a specified file?

在我的.htaccess文件中,我具有以下RewriteRules:

RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
RewriteRule ^site/(.*) error [R=301,L]

它們非常適合阻止直接訪問txt|md|mdown文件類型和整個site/目錄。

也就是說,我正在構建一個.appcache文件以緩存我的站點以供脫機查看,並且需要能夠從.appcache文件訪問這些文件和目錄。 我已設置.appcache文件,並且在瀏覽器中遇到以下錯誤:

Application Cache Error event: Resource fetch failed (-1) http://website.com/site/panel/blueprints/home.php

是否可以更新RewriteRule以允許從該文件進行訪問?

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com.br/.*$ [NC]
RewriteRule .*\.(pdf|cdr|indd|psd|jpg|jpeg|ai|zip|rar|7z)$ - [F]

只需將yoursite.com替換為您的站點,並將。* $替換為所需的特定文件即可。

<Files "file_name.appcache"> 
  // rewrite yours in it
</Files>

希望能幫助到你 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM