Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following mod rewrite script, I want to change it to try looking for a file in a particular directory, can somebody give me a hint on how to achieve this please?

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

The rewrite needs to check if the filename exists in the requested location, then if that fails it will check in directory like '/themes/theme1', and finally it will go to /index.php when the above two fail.

share|improve this question
up vote 1 down vote accepted

To check to see if a directory exists, use:

RewriteCond /path/to/directory -d 

For a file, use

RewriteCond /path/to/file -f
share|improve this answer
Hi tylerl, how do I add the requested filename to the end of those RewriteCond statements? And how do I write the rewrite rule to rewrite the location of the file? Example request: /path/to/directory/css/styles.css – dallasclark Oct 6 '10 at 10:50
Here's the documentation: – tylerl Oct 6 '10 at 17:46
Thanks, I ended up using the RewriteRule instead and it works RewriteRule ^css/(.*)$ path/to/directory%{REQUEST_URI} [L] – dallasclark Oct 7 '10 at 11:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.