Re: htaccess and indexes

by David Sharp <David.Sharp(at)sharp-words.com>

 Date:  Tue, 21 Aug 2001 07:03:15 +0200
 To:  <hwg-techniques(at)hwg.org>
 References:  apple Server
  todo: View Thread, Original
At 23:45 -0400 20/08/01, Jeff at Data Driven Design wrote:
>This might be what you're looking for.
>
>http://httpd.apache.org/docs/mod/mod_dir.html#directoryindex

Ah! - 'twas staring me in the face and I didn't see it. Many thanks.

My .htaccess file now reads:

ErrorDocument 404 /error.phtml
DirectoryIndex /index.phtml

The second line indeed prevents users from seeing the contents of 
each directory, and reroutes them to the sole index file of the site, 
which is at the root.

Example: the address http://www.presse-en-ligne.com/site/ now returns 
the contents of http://www.presse-en-ligne.com/

The only minor change I've had to make is making the path to my 
stylesheet absolute, because Apache "thought" it was relative to the 
subdirectory, and wasn't finding it in the rerouted pages.

So that instead of reading:
><link rel="stylesheet" type="text/css" href="css/default.css" title="default">

my <link> tag now reads:
><link rel="stylesheet" type="text/css" href="/css/default.css" 
>title="default">


NB: A different suggestion, sent privately, proposed:

Options -Indexes
ErrorDocument 403 /index.phtml

This seems to work also, but the "DirectoryIndex" directive looks 
simpler to my inexperienced eyes.

At 15:48 -0400 20/08/01, Marian Cole wrote:
>You can do this in Javascript by putting this text in the page called
>index.html:
>
><script>
>location.replace("http://www.error-page-url.html");
></script>
>
>or use meta redirect within the page head to do the same thing:

and at 19:26 -0400 20/08/01, howardm wrote:
>Why not add an index page to those directories with a re-direct to 
>the index page you want them to see?

Thanks, but those were precisely the kind of things I wanted to avoid.

I'd rather have the server do the work rather than having to think 
about putting an index file into each directory that someone might 
decide to peek into

As regards JavaScript, I avoid it wherever possible - ie practically 
all the time.

At 17:44 -0700 20/08/01, Larry Goodwin also wrote:

>The .htaccess file is slower than using the Apache config file.

Yes, but as a humble client of a hosting service, I don't think I 
have access to the latter.

Best wishes,


-- 
David Sharp, journalist(e), France <mailto:david.sharp(at)sharp-words.com>
Site personnel / Personal home page http://www.sharp-words.com/
Site et forum  / Press site & mailing list: http://www.presse-en-ligne.com/

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA