Jamie
Jamie

Reputation: 1094

.htaccess option -indexes redirect?

In .htaccess, we can use this code :

Option -Indexes

to protect people loading our directory.

However, how can we do this ?

Option -Indexes [redirect to /index.html]

Any help will be appreciated. Thanks.

Upvotes: 1

Views: 1304

Answers (1)

arkascha
arkascha

Reputation: 42935

You just rewrite all requests to directories to your index page:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ /index.html [R=301,L]

(wrote this without having a system at hand, hope there's no typo...)

Explanation: since automatic indexes are only generated when a directory is requested by the browser, this should be safe. I am currently not sure about the implications of .htaccess style file usage. This also makes rewriting complex, error prone and slooooow. If you have access the real server configuration always prefer that!

Upvotes: 2

Related Questions