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


  • viralthakkar 10 March, 2009, 19:11

    this is really helpful details

  • Ricardo Zea 18 December, 2009, 7:38

    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 18 December, 2009, 18:31

      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.

  • Ricardo Zea 19 December, 2009, 10:12

    Awesome! It worked perfectly!

    Thanks Viral!

  • Trupti 6 May, 2010, 12:40

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

  • Eli 15 June, 2010, 16:28

    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.


  • Dan 5 November, 2010, 23:39

    Great! thanks!

  • Sachin 13 January, 2011, 21:21

    Nice mate.. :)

  • Vas 3 October, 2011, 22:26

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


    • Vas 3 October, 2011, 22:34

      OK, I see the answer above.. :)

  • takprosto 20 October, 2011, 7:11

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

  • Visakh 20 October, 2011, 7:22

    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.

  • Ramratan Gupta 25 May, 2012, 17:58

    Thank You

  • Dom @elevate 20 July, 2012, 17:52

    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

  • Ronald Sayerse 8 August, 2012, 23:45

    Thank you very much mate!

  • Randell 21 September, 2012, 9:19

    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

  • lee 14 October, 2012, 17:50

    I added a new line ‘Options -Indexes’ in each .htaccess files,but the directories still display on browser. Can anybody give some more suggests? Thanks very much. is my address.Hoping for that…

  • Jamesd 15 October, 2012, 20:53

    Cheers – took a while to track this down!

  • Julien 16 October, 2012, 21:16

    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

  • Paulo 25 October, 2012, 9:06

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

  • Carmen 21 November, 2012, 19:27

    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

  • babu 20 December, 2012, 10:20

    It’s really helpful for me, Thanks:)

  • Jorge Muralles 19 February, 2013, 6:34

    Hello everyone.

    I got directory browsing working on my website.

    I get a broken picture icon next the directories and files.

    Here is the link:

    I put this code in the .htacces file

    Options +Indexes
    IndexOptions +FancyIndexing

    It does not do the job.

    Can anyone help.

  • Victor 13 March, 2013, 2:07

    Thank you very much. This tutorial was very helpful.

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

  • Bumba 15 March, 2013, 13:10


  • Akarsh 19 May, 2013, 23:52


    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.

  • Jan 4 June, 2013, 15:39

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

  • Anand 26 July, 2013, 18:07

    Thanks!! really helpful.

  • Waldemar 21 September, 2013, 1:39

    How to allow directory access for all by htaccess?

  • jagadeesh 18 November, 2013, 17:20

    thanks a lot really helpful to me

  • Jarod Thornton 24 January, 2014, 9:24

    Thank you! This was very useful.

  • Arnaud 30 January, 2014, 21:33

    Useful post thanks

  • chris lee 6 February, 2014, 6:42

    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.

  • SM. Kafi 4 May, 2014, 22:49

    Thanks, its really a good job…….

  • Vivek Moyal 29 May, 2014, 18:39

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

  • jagadeesh 12 July, 2014, 15:45

    very useful content. thank you…

  • obaid 29 December, 2014, 15:29

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


  • KRISHNA TEJA 30 December, 2014, 17:17

    Thanks bro, it really helped me well….

  • PNR Status Check 12 January, 2015, 9:41

    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.

  • Alexander 9 February, 2015, 0:49

    How to Directory access for all htaccess?

Leave a Reply

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


To post source code in comment, use [code language] [/code] tag, for example:

  • [code java] Java source code here [/code]
  • [code html] HTML here [/code]