In: , , , ,
On: 2004 / 05 / 08 Viewed: 72574 times
Shorter URL for this post: http://ozh.in/z

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)

CODE:
  1. RewriteEngine  on
  2. RewriteBase    /
  3. RewriteCond    %{REQUEST_FILENAME}  -d
  4. 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

Metastuff

This entry "Apache and the trailing slash problem" was posted on 08/05/2004 at 7:58 pm and is tagged with , , , ,
Watch this discussion : Comments RSS 2.0.

12 Blablas

    Pages: [2] 1 » Show All

  1. 12
    What is Apache? Europe »
    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?

  2. 11
    David Bell United Kingdom »
    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

Pages: [2] 1 » Show All

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

Close
E-mail It