htaccess with RewriteRule允许对特定文件夹的请求


htaccess with RewriteRule allow request to a specific folder

我已经构建了自己的MVC框架,我有以下.htaccess配置:

Options -MultiViews
RewriteEngine On
RewriteBase /site/public/zone/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

传递给$url变量的所有内容都分解成一个数组,然后我从第一个值中选择控制器。

然而,在"区域"文件夹中,我有另一个名为"res的文件夹,它有不同的资源,如照片和视频,我想直接访问它们。

我应该如何配置.htaccess文件,使其像现在一样重写所有内容,但允许直接请求"res"文件夹中的资源?

您可以添加这样的lookahead condition

Options -MultiViews
RewriteEngine On
RewriteBase /site/public/zone/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!zone/res/).+)$ index.php?url=$1 [QSA,L,NC]