使用.htaccess指令绕过框架提供资源文件

时间:2014-02-06 19:53:22

标签: apache .htaccess http

我正在使用Kohana框架。它具有.htaccess文件的以下配置:

# 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 [PT]

我特别感兴趣的是第二部分Allow any files or directories that exist to be displayed directly。有人可以详细说明它是如何配置的吗?

1 个答案:

答案 0 :(得分:0)

这是由于2个条件行使用RewriteCond指令,其作用类似于if condition

RewriteCond %{REQUEST_FILENAME} !-f

表示请求不是有效文件

RewriteCond %{REQUEST_FILENAME} !-d

表示请求不是有效目录

两者结合下面的RewriteRule表示如果请求不是有效的文件或目录,则将每个请求转发到index.php