允许访问 .htaccess 中的某些目录和文件


allow access to certain directories and files in .htaccess

我有一个带有MVC和.htaccess文件的php应用程序,它重新复制了指向文件索引的所有链接.php但我需要访问其他文件夹和文件,如公共/css、公共/js、公共/图像和奥瑟......

大多数 MVC 规则都包含以下内容:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

这是为了防止指向实际文件的 url 被重写到 mvc。例如,如果要直接链接到public/css,而是链接到/css,则需要在MVC规则之前放置一个规则,如下所示:

RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(css|js|images)/(.*)$ /public/$1/$2 [L]

这会在内部将/css/some/stylesheet.css重写为 /public/css/some/stylesheet.css

您应该添加一个允许访问这些目录的条件。

# Requested filename does NOT contain index.php, resources, or robots.txt
RewriteCond $1 !^(index'.php|resources|robots'.txt)
# Requested file does NOT exist
RewriteCond %{REQUEST_FILENAME} !-f
# Requested directory does NOT exist
RewriteCond %{REQUEST_FILENAME} !-d
# If all the above rules are true, redirect to index.php/$1
RewriteRule ^(.*)$ index.php/$1 [L,QSA]