Apache Mod Rewrite – exclude folder and subfolders, except for one subfolder

apache-2.2mod-rewrite

I have a Mod_Rewrite setup as follows:

RewriteCond %{REQUEST_FILENAME} !^/www/live/site.name/app/public/(/forms/|/crm/)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

Routing all requests – except for the /forms/ and /crm/ folder through an index.php file which loads the framework/routing etc.

However, now I have to allow /forms/apply/ to also be routed to the index.php – but anything else in /forms/ should continue to be ignored.

Any suggestions?

Best Answer

You can use the OR condition:

RewriteCond %{REQUEST_FILENAME} ^/www/live/site\.name/app/public/forms/apply/ [OR]
RewriteCond %{REQUEST_FILENAME} !^/www/live/site\.name/app/public/(forms/|crm/)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

By the way . need to be escape, and you had a / in more in /forms/ & /crm/

Related Topic