November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Rewrite only if a folder exists

RewriteCondthat checks if the requested file exists:

RewriteCond %{REQUEST_FILENAME} !-f

Great, but that’s not what I was looking for. Instead I needed to Rewrite only if a specific folder existed. The solution turns out to be this:

RewriteCond %{DOCUMENT_ROOT}/path/within/your/project/ -d

You need DOCUMENT_ROOT as the RewriteCond -d checks for the full path

 

<IfModule mod_rewrite.c>

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>