Skip to content
Advertisement

How to list a directory content

How to access directory files when we don’t have index file.

I used this htaccess code but it worked when I mention file but I want to show directory file without insert index file.

Please check my htaccess code and tell me where i am wrong thanks

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ check.html?url=$1 [QSA,L]

Advertisement

Answer

You can use the Options configuration option. The documentations presents Options by saying

Configures what features are available in a particular directory

You can use many options, the one you are looking for is Indexes. To add this option you need the instruction Options +Indexes.

In an .htaccess file you can use it simply by putting this.

# Allows Apache to list the directory content
Options +Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ check.html?url=$1 [QSA,L]

In a vhost file it could be like this.

<Directory /var/www/html/mysite>
  Options +Indexes
</Directory>

I suggest to use this in your vhost file though.

As said in comment it’s recommanded to configure a site in a vhost file. If you can (if your host allows you), use the vhost instead of the .htaccess file. If you can set all your configuration in your vhost and avoid using .htaccess, you can use AllowOverride None to forbid the .htaccess usage then.

See the wiki and the documentation.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement