views:

180

answers:

3

I'm wanting to use .htaccess to prevent directory listing. I've got pages within /location/ but I don't have an index file. So Im wanting to redirect to /location/about.php for example.

Is there a way to do this, without creating a index.html and redirecting requests to that? Thanks for the help!

A: 

Okay, so I guess somebody doesn't appreciate the humor of "Let me Google that for you." I didn't mean to be rude, so I apologize if it came off that way.

Here is a direct link to what you need:

http://www.webweaver.nu/html-tips/web-redirection.shtml

If you need something more advanced to handle parameters or need to remap old URLs to new ones, you can use URL rewriting:

http://corz.org/serv/tricks/htaccess2.php

Prevent directory listing (or return an empty directory listing):

http://www.besthostratings.com/articles/prevent-directory-listing.html

rob
Im not wanting to redirect a page, im wanting to redirect a directory to a page. However if I redirect a whole directory, every page within that directory will point to the redirected page. Or so I am to belive.
Jamie
+3  A: 

If you're asking for a file in place of 'index.html', see "DirectoryIndex" to tell it what files to use in place of 'index.html':

DirectoryIndex about.php index.html
Options –Indexes

... if you're trying to redirect all directories to a single page, then I'd cheat and do the following, which will mostly do what you're asking for:

Options +Indexes
IndexOptions +SuppressHTMLPreamble
IndexIgnore *
HeaderName /includes/header.html
ReadmeName /includes/readme.html

... and set /includes/header.html with whatever message you want (or containing a meta-redirect), and /includes/readme.html to be blank.

Joe
I used the first example. However including Options -Indexes resulted in a internal server error. So I just used DirectoryIndex to replace the default .html then reflected this in each directory nessecary. Thanks!
Jamie
A: 

Changing DirectoryIndex and Options works, but using mod_alias means that you don't have to change it back in nested directories.

Redirect 303 /location/ /location/about.php
Justin Johnson