Lelio Faieta
Lelio Faieta

Reputation: 6673

htaccess to exclude a specific directory

I have a htaccess at the root of my site like this:

RewriteEngine On

RewriteRule \.php$ - [L,NC]

RewriteRule ^(?:favicon\.ico|(?:index|custom500|custom404)\.html)$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?source=$0 [L,QSA]

I want it to ignore those urls that contain a specific folder folder1. Urls will be like:

https://mycooldomain.com/folder1/api/rest/... //something else here

I have examined this question but I seem not able to apply it to my situation.

Upvotes: 2

Views: 270

Answers (2)

MrWhite
MrWhite

Reputation: 45829

Alternative to @anubhava's answer... the only rule that needs to be ignored in your .htaccess file is the last one. So you could just add a condition to that last rule to exclude URL-paths that start /folder1/.

For example:

RewriteCond %{REQUEST_URI} !^/folder1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?source=$0 [L,QSA]

The ! prefix on !^/folder1/ negates the regex, so it is successful when it does not match. ie. when the URL-path does not start with /folder1/.

Upvotes: 2

anubhava
anubhava

Reputation: 785128

Have it like this:

RewriteEngine On

# ignore request URLs that start with /folder1/
RewriteCond %{THE_REQUEST} \s/+folder1/ [NC]
RewriteRule ^ - [L]

RewriteRule \.php$ - [L,NC]

RewriteRule ^(?:favicon\.ico|(?:index|custom500|custom404)\.html)$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?source=$0 [L,QSA]

Upvotes: 3

Related Questions