Search code examples
.htaccessdirectoryfilelist

How can I suppress viewing / listing all file types EXCEPT html files using .htaccess?


Basically I want to go beyond simple "Options +Indexes" display on a server, set using the .htaccess file.

I ONLY want to see .html files in a given directory, and suppress display of ALL OTHER file types.

Why? I am happy to show directory listing pages on a testing server, so a client can select different page design versions, for instance...

BUT I would prefer they just see the '.html' files on the directory listing, NOT any other image files, favicon files and so on.

Any clues much appreciated, not that familiar with .htaccess possibilities.

thanks!


Solution

  • The only way is to use IndexIgnore carefully . For example ,if you put the following code :

    Options +Indexes
    IndexIgnore  *
    

    The directory listing will be on but nothing will be shown so the use of IndexIgnore is to hide what you want when directory listing is done .

    Another example is to do the following :

    Options +Indexes
    IndexIgnore  *.php *.jpg *.png  *.txt *image
    

    The code above will hide all files with these extensions as well as image folder , so you should exclude all folderes and files that you don't want them to be shown , .html files are not listed above so,they will be shown.