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]
</IfModule>

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.

link|improve this question

22% accept rate
feedback

1 Answer

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
link|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: httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond – 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
feedback

Your Answer

 
or
required, but never shown

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