Rewrite urls.. except files.. except dir ? :P

is it possible to give access to directory / files except files inside /themes directory… then still rewrite to index.php ?

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php


Yes, but ONLY if the file/directory exists.

BTW, the regex for the RewriteRule will not match just a domain request (without making the {any character} optional) so you must rely on the DirectoryIndex to get to index.php.



:smiley: how?

Maybe I am not explaining it right…

How can I add an exception to this line:

RewriteCond %{REQUEST_FILENAME} !-d


You DON’T! You merely add another exception with RewriteCond %{REQUEST_URI} !themes/ either before or after the other RewriteCond (they’re ANDed so order makes no logical difference).



Thanks again David, this is exactly what I came looking for today. :slight_smile:
Using something similar to this (for example)

RewriteCond $1 !^(Contacto¦En/Contact)\\.html$ [NC]

wasn’t working out (after being modified a bit)
Your way:

RewriteCond %{REQUEST_URI} !example/

Worked the on the first try.