[Gllug] Apache Trailing Slashes
Simon Morris
simon.morris at penguinit.com
Tue May 6 07:13:00 UTC 2003
Hi All,
Trying to solve the age old Apache problem of the trailing slash
http://www.domain.com/folder == results in an error message
http://www.domain.com/folder/ == resolves because of the trailing slash
I've looked on the Apache documentation and found the following.....
Trailing Slash Problem
Description:
Every webmaster can sing a song about the problem of the trailing
slash on URLs referencing directories. If they are missing, the server
dumps an error, because if you say /~quux/foo instead of /~quux/foo/
then the server searches for a file named foo. And because this file
is a directory it complains. Actually it tries to fix it itself in
most of the cases, but sometimes this mechanism need to be emulated by
you. For instance after you have done a lot of complicated URL
rewritings to CGI scripts etc.
Solution:
The solution to this subtle problem is to let the server add the
trailing slash automatically. To do this correctly we have to use an
external redirect, so the browser correctly requests subsequent images
etc. If we only did a internal rewrite, this would only work for the
directory page, but would go wrong when any images are included into
this page with relative URLs, because the browser would request an
in-lined object. For instance, a request for image.gif in
/~quux/foo/index.html would become /~quux/image.gif without the
external redirect!
So, to do this trick we write:
RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]
The crazy and lazy can even do the following in the top-level
.htaccess file of their homedir. But notice that this creates some
processing overhead.
RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
============================
The above all sounds fine but how do you do it for the entire site. The
above rewrite rule would only work for foo folder under /~quux/.
Wouldn't it?
--
Simon Morris
simon.morris at penguinit.com
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list