.htaccess on 000webhost options

Viewed 340

I am trying to modify my .htaccess file in 000webhost in order to disable Indexes option only for a specific folder (because it is enabled by default).

I have all the following files in public_html/ folder:

  • nas/ (empty directory)
  • test/ (empty directory)
  • .htaccess

I would like to disable the Indexes options in test/ folder, but keep that option enabled on nas/. I have tried with the following Directory container but it makes the site crash:

<Directory /public_html/test/>
    Options -Indexes
</Directory>

I have been trying many different paths (because as far as I know, 000webhost uses virtual routers, but I can't find the way to do it).

Thank you so much!

2 Answers

If you are willing to disable the Indexes option for /test folder you can go with

<Directory "/public_html/test/">
    Options -Indexes
</Directory>

Option -Indexes will remove completely the access to the test folder in the repo.

If you want to keep the Indexes option for only /nas folder so that outsider can have access to this folder contains then you can go with the following

<Directory "/public_html/nas/">
   Options +Indexes
</Directory>
<Directory /public_html/nas/>
    Options -Indexes
</Directory>

The <Directory> directive is not permitted in .htaccess (hence your 500 error). <Directory> containers can only be used in a server or virtualhost context. The .htaccess file itself is the equivalent of the <Directory> container. (But why are you trying to target the /nas directory here, since it would seem to be the /test subdirectory that you want to disable directory listings for?)

You will need to create another .htaccess file in the /test subdirectory in which you disable directory listings:

# Disable auto-generated directory listings (mod_autoindex) for this directory only
Options -Indexes

Now, you'll just get a 403 Forbidden when accessing the /test subdirectory.

Alternatively, if you don't want to create another .htaccess file in the subdirectory then you'll need to use RedirectMatch (mod_alias) or RewriteRule (mod_rewrite) to block that specific URL. For example, in the root .htaccess file:

RewriteEngine On

RewriteRule ^test/?$ - [F]

The above will also trigger a 403 when attempting to access the /test/ subdirectory directly (just as if the Indexes option were disabled for that subdirectory). All files within that subdirectory (if any) are still accessible.

Related