简体   繁体   中英

htaccess with RewriteRule allow request to a specific folder

I've build my own MVC framework and I have the following .htaccess configuration:

Options -MultiViews
RewriteEngine On

RewriteBase /site/public/zone/

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

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Everything that is passed to the $url variable is exploded in an array and then I select the controller from the first value.

However in ' zone ' folder I have another folder called ' res ' that has different resources like photos and videos that I want to access them directly.

How should I configure the .htaccess file so that it rewrites everything as it does now but allow direct request to those resources that are in ' res ' folder?

You can add a lookahead condition like this:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM