我如何使用htaccess Kohana 3.2应用程序保护文件夹



大家好,我需要帮助,我在我的应用程序中使用 Kohana,并创建了一个名为 media 的根文件夹到 imgs、css 和 js,所以我想保护访问它,而没有网站运行的 url,这样做吗?

例:

  • 应用文件夹
  • 系统文件夹
  • 模块文件夹
  • 媒体文件夹(我需要保护此文件夹)
  • 索引.php

我的文件 .htaccess 在根目录中是:

# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

你说的是热链接。

返回 403 禁止使用 .htaccess(假设 example.com 是你的域名):

RewriteEngine On 
RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/ [NC] 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteRule .(jpe?g|gif|bmp|png|js|css)$ - [F] 

这是一个特殊的生成器:http://www.htaccesstools.com/hotlink-protection/

最新更新