I am using mod_rewrite to pass identifiers to my web app in the form:
http://clipi.ca/1W
I am identifying these with a simple regex:
RewriteCond %{REQUEST_URI} ^/([0-9a-zA-Z]+)$
RewriteRule ^(.*)$ /index.php?urlid=%1 [L,QSA]
…which works fine in most cases. However I noticed that when the identifier is the name of a directory, the rewrite is failing and Apache is returning a directory index!
How can I stop this behavior and have the rewrite rule apply to directories as well? (Note that as soon as an actual file inside a directory is referenced, the rewrite condition fails and it is not a problem.)
I think I may have figured it out myself: Apparently, Apache will append a trailing slash to requests that map to directories on the filesystem before it applies any rewrite rules. That’s kind of silly, imo, but by adding an optional trailing slash to my conditional regex:
…it seems to be working!
Still, the ideal solution would be to get Apache to not append that trailing slash to begin with. If anyone knows how to do that, post it here and I’ll give you the answer credit.