For aesthetic reasons (I prefer when there is a strict one-to-one mapping between URL and pages), I do not like the fact that http://www.example.com/index.html and http://www.example.com/ yield the same content with two different URLs. I would like to have http://www.example.com/ as the canonical one.
The obvious solution:
Redirect permanent /index.html /
is wrong (endless loop).
A better solution? It seems surprisingly difficult.
Try a
RewriteCond
from mod_rewrite:This says if the query string is not
/
then rewrite/index.html
as/
(should not loop).My solution (which seems to work so I accepted it), inspired from PP's response, is:
Any non-modrewrite solution? I had to activate a new Apache module, which I try to avoid.
RedirectMatch ^/index.html$ http://www.example.com/
Why not set DirectoryIndex to something else - e.g., unpredictable.html, and name your index file similarly?
You need never expose the chosen DirectoryIndex value.
Note that the last argument to Redirect needs to be a full URL, not just a path fragment.
A non mod_rewrite solution… Actually joschi nearly had it but for some (unclear to me) reason you have to kludge around the endless loop:
perfect solution