Reputation: 73
I want to disable a directory listing using .htaccess.
I don't want to show any 404 not found
or 403 forbidden
error messages.
Suppose when a user will try to access the directory www.mydomain.com/data/uploads
, then only a custom message will show like Hi, this is not a page you are looking for
.
Can anybody help me?
Upvotes: 2
Views: 1109
Reputation: 17886
An alternative option, which would send a 200 response and not use a custom errordoc for any other 403 in the same context, would be to set a low priority DirectoryIndex with your custom error message.
Options -Indexes
DirectoryIndex index.html lastchance.html
Upvotes: 1
Reputation: 785276
You can use this code in your .htaccess:
# disable directory listing
Options -Indexes
# show a custom message
ErrorDocument 403 "Hi, this is not a page you are looking for"
Upvotes: 1