I use Apache's mod_rewrite extensively on my site to generate clean URLs. It is basically matches a regex to a url (similar to Django's URLConf). I noticed that, while links like /news/ worked fine, /news (without the backslash) would generate a 404. To fix this, at the bottom of my .htaccess file, I added the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)[^\/]$ $1/
This snippet tests for a 404 condition (no matching file or directory) and if it is true, it tries the RewriteRule, which basically will take any URL that does not end in a backslash and try appending one. Works great!
Comments (0)
Commenting has been disabled for this entry
If you'd like to discuss an aspect of this post, feel free to contact me via email.