Search code examples
.htaccessmod-rewriteapache2.4

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.


Solution

  • 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]