views:

27

answers:

1

I am building a .htaccess file with a fairly complex ruleset.

One of the basic rewriting rules is this first line:

If a requested file exists physically, no rewriting, stop processing rules.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

this works well with one exception: When I access a directory with a trailing slash

www.example.com/directory/

directory will not be recognized as existant, whereas

www.example.com/directory

will.

What can I do to make Apache recognize existing directories with a trailing slash as well?

Background info, I am already adding trailing slash to every request made without one (to cater for both /directory and /directory/ requests.

+1  A: 
RewriteCond %{REQUEST_FILENAME} -d

The -d stands for directory. Also, according to http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite , the [L] directive doesn't work in .htacess files, just if you put it in your apache conf files.

Also if you simply start off with:

RewriteEngine on
# Dont rewrite files or directories which actually exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

You can avoid rewriting any existing files or directories. Your existing rules says "If this is a real file, keep going" whereas mine says "If its not a real file and its not a real directory, keep going."

Erik
Brilliant, thanks a lot. [L] not working in .htaccess explains a lot too. I'm off for now, will test this tomorrow.
Pekka
Sadly, this won't work either! Strange.
Pekka
Can you post your entire .htaccess? The second group of lines I posted starting with `RewriteEngine on` is exactly what i use to redirect any file or directory which does not exist to a specific file (with the unshown rewrite rule).
Erik