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.
said, on 08/May/04 at 8:31 pm # :
Mais si Apache ne supporte pas le mode rewrite ? :P
And if Apache doesn't support rewrite mod ? :P
wrote, on 08/May/04 at 8:49 pm # :
bah, baisé :P
Well, fucked :P
commented, on 08/May/04 at 11:06 pm # :
De toutes façons, linux, Apache et PHP ça pue vivent windows server 2003, IIS et ASP ...
Anyway, Linux, Apache and PHP suck, Win Server 2k3, IIS and ASP are the best ...
:-X
wrote, on 10/May/04 at 6:38 pm # :
IIS? on Winblows? You must be kidding me :p
replied, on 10/May/04 at 7:02 pm # :
Sure I'm :)
said, on 28/Jun/04 at 7:00 pm # :
euh, perso je ne fait jamais confiance au serveur, c'est pourquoi j'écris en dur les paramètres du site sous forme de constantes dans un fichier config chargé à chaque page
c plus propre, et puis il paraît que les htaccess ralentissent les serveurs
thought, on 02/Jul/05 at 10:55 pm # :
I retract my previous comments about Windows being the best. Turns out it sucks cock as hard as I do.
commented, on 21/Jun/07 at 3:23 am # :
any tips on how to get this working in a subdirectory? i have wordpress installed on my root and your fix seemed to be working very well. then i installed another installation under /blog/ and when i enabled pretty permalinks, it looks like the .htaccess file that is created under the /blog/ dir by wordpress is overriding the functionality of the .htaccess in the root dir.
wrote, on 22/Jun/07 at 11:05 pm # :
josh » had the same problem with my previous host. The workaround is simple: add this .htaccess trick to /.htaccess and /blog/.htaccess (before what WP inserts in this file)
Other subdirectories though (/download or whatever that's not WP) shouldn't need the extra .htaccess trick.
pingback on 12/Jul/07 at 10:45 am # :
[...] have tried searching the web and found this (link1) while Dorkarl from Google Group also referred me to [...]
replied, on 12/Oct/07 at 11:29 am # :
Thanks Ozh, that worked beautifully for me... Been struggling with the trailing slash for days!
Merci
replied, 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?