Directory listing in htaccess. Allow, Deny, Disable, Enable Directory Listing in .htaccess

When a web browser is pointed to a directory on your web site which does not have an index.html file (or any other index file) in it, the files in that directory can be listed on a web page.
Let us see few snippets that can be added in htaccess file to allow or avoid directory listing in apache server.

Enable / Disable directory Listing

To allow a web server to produce a directory listing, whenever you point a directory without index file. Add following line in your .htaccess file.

Options +Indexes 
# or #
IndexIgnore *


To disable or prevent the directory access add following line in your .htaccess file. If user points the browsers to a directory which does not have index file then in this case 403 error will be

Options -Indexes 

Following is the error page that gets displayed when we try to access any directory without index file.

Change Listing style

You may want to display other details while showing the directory listing. This includes file icons, file size, modification date and more. This can be done by adding fancy style to your htaccess file. Add following snippet in .htaccess file.

IndexOptions +FancyIndexing


To remove the fancy directory listing or to display normal directory listing, use -FancyIndex.

IndexOptions -FancyIndexing

Ignore files with specific extension

It may happen that you may need to ignore certain files to get displayed in directory listing. This can be achieved using IndexIgnore directive in .htaccess file.
Following snippet will not display .zip and .txt file in directory listing.

IndexIgnore *.zip *.txt

Modify Index File

It is possible to change the default index file from index.html (index.php, index.jsp …) to any other file. Following line will change the index file to Home.html.

DirectoryIndex Home.html
Get our Articles via Email. Enter your email address.

You may also like...


  1. viralthakkar says:

    this is really helpful details

  2. Ricardo Zea says:

    Is there a way to disable all browsing all directories except one?

    For example, after applying “Options -Indexes”, can I create a rule to list items inside the ‘/pdf’ folder?


    • Viral Patel says:

      Hi Ricardo,
      There is a way to achieve this. If you want to disable directory listing in a folder and all its subfolders except one subfolder say /pdf. You have to create .htaccess file in root folder and the code to disable directory access: Options -Indexes. And then create another .htaccess file in the subfolder /pdf and add code to allow directory listing in it: Options +Indexes.

  3. Ricardo Zea says:

    Awesome! It worked perfectly!

    Thanks Viral!

  4. Trupti says:

    Thanks Viral, I was looking for a solution for what Ricardo asked, and yours worked perfectly. Thanks! :)

  5. Eli says:

    The IndexIgnore * line seems to cause the whole thing not to work. This line tells the server to ignore all files in the directory listing. When I took out that line, I was able to see the directory properly.


  6. Dan says:

    Great! thanks!

  7. Sachin says:

    Nice mate.. :)

  8. Vas says:

    That’s very good information.
    But, is there a way to set these listing permissions per directory, instead of document root?


    • Vas says:

      OK, I see the answer above.. :)

  9. takprosto says:

    When I took out that line, I was able to see the directory properly.

  10. Visakh says:

    I have a problem in directory listing in it doesn’t show a single file in the folder. I have updated .htaccess file and pasted Options +Indexes. then also it is showing blank page. What should i have to do.

  11. Thank You

  12. Dom @elevate says:

    Got this to work where you deny public access but allows internal processes. Place this in the htaccess of the folder you want to restrict access to:

    order deny,allow
    deny from all

  13. Thank you very much mate!

  14. Randell says:

    hi mate,

    im using Clipbucket for a music site im building now clipbucket has like tons of Stuff in httacess file and the bulk of it’s stopping anyone from doing stuff they shouldn’t using scripts in url Ect exploits and it also blocks access to pages that clipbucket doesn’t use in it’s script this also means every folder i add on to the site Will not work, How would i block everything else or keep it the same i guess yet still allow access to Say /Forum or any extra folders i tack onto my domain, ? thanks in advance

  15. Jamesd says:

    Cheers – took a while to track this down!

  16. Julien says:

    Hi guys

    I have the same problem with a folder of my website.
    I wrote the “Options -Indexes” in the root folder’s htaccess
    and “Options +Indexes” in the folder /download (where I want all files to be listed)

    The website works fine, but I get an error 500 while accessing to the /download folder

    I’m hosted by OVH, but I can’t read anything about that in their forums

    Thanks a lot !
    Have a nice day

  17. Paulo says:

    THANK YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  18. Carmen says:

    I have a problem, I need to protect some folder in my web through validation, i created an .htaccess and put it in this folder but this dissapear of my navigation tree , what is the the way that this folder appear again? but keeping the validation through user/passwd

  19. babu says:

    It’s really helpful for me, Thanks:)

  20. Victor says:

    Thank you very much. This tutorial was very helpful.

    I was looking for the function that prevented access to directories of my website.

  21. Bumba says:


    • Bumba says:


  22. Akarsh says:


    I have an issue.
    I need to prevent DIRECT access to all .swf files in “localhost/mysite/sitesong/” directory [http://localhost/mysite/sitesong/abc.swf] but it should be able to be accessed if localhost/mysite/song.php is linking it inside tag.

    For this, the following code is added in /sitesong/.htaccess file

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://(www.)?localhost/mysite [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www.)?localhost/mysite/.*$ [NC]
    RewriteRule .(swf)$ - [F]

    This code works for the Firefox and Chrome browser but in IE, though the .swf file is prevented from directly accessed but /song.php also is unable to access the swf files.

    Any help would be appreciated.

  23. Jan says:

    Thanks! Works like a charm! No more access to folders. (:

  24. Anand says:

    Thanks!! really helpful.

  25. Waldemar says:

    How to allow directory access for all by htaccess?

  26. jagadeesh says:

    thanks a lot really helpful to me

  27. Thank you! This was very useful.

  28. Arnaud says:

    Useful post thanks

  29. chris lee says:

    Thank a lot! This was really helpful.

    I am using a hosting service at bluehost and there

    AddHandler application/x-httpd-php .html .htm

    seems to work.

  30. SM. Kafi says:

    Thanks, its really a good job…….

  31. Vivek Moyal says:

    I was using Options -Indexes but i got 404 error….. i am also hiding the extension of the page ….

  32. jagadeesh says:

    very useful content. thank you…

  33. obaid says:

    why this htaccess not working under my svn path and using full path
    still displaying indexing even after placed htaccess in project1


  34. KRISHNA TEJA says:

    Thanks bro, it really helped me well….

  35. PNR Status Check says:

    I want don’t to index robots.txt, sitemap.xml and some specific pages. Will you tell me, how can I do it through htaccess? Any suggestion will be appreciated; thanks in advance.

  36. Alexander says:

    How to Directory access for all htaccess?

  37. parvinder says:

    Hello Admin,

    I have a .bar website and I added ‘Options -Indexes’ in .htaccess file but still my all inner directory access by anyone. Can you please tell me what should I do for disable inner directory.

    Waiting for your reply!

Leave a Reply

Your email address will not be published. Required fields are marked *