On badly configured Apaches (like on errr... my host :), URLs referecing directories and lacking a trailing slash (like /mydir instead of /mydir/) lead to an error : the webserver looks for a file named mydir instead of a directory.
After some googling and lots of testing, I've come up with a solution. This should even work on Apaches with virtual hosts enabled and bad ServerName directive.
Put this in .htaccess in your document root (given example is for my site of course, replace the server name with yours)
-
RewriteEngine on
-
RewriteBase /
-
RewriteCond %{REQUEST_FILENAME} -d
-
RewriteRule ^(.+[^/])$ http://frenchfragfactory.net/$1/ [R=301,L]
Of course, you need mod_rewrite and the ability to override these settings in your .htaccess file.
Related posts
Shorter URL
Want to share or tweet this post? Please use this short URL: http://ozh.in/z
Pages: [2] 1 » Show All
said, on 23/Nov/07 at 11:04 pm # :
Why do this? Doesn't this overload Apache, as now it has to serve two requests? What is the advantage?
commented, on 12/Oct/07 at 11:29 am # :
Thanks Ozh, that worked beautifully for me... Been struggling with the trailing slash for days!
Merci