How to stop directory listing or Index browsing in Wordrpress via htaccess

Disabling of directory browsing in WordPress is necessary to mitigate the vulnerability attacks since it shows all available files in the content directory.

Now, What is directory browsing in WordPress?

Once we installed and access our web server using a browser, by default it immediately looks for index.php or html to show something, however, if any of them is not available, it will display other files of the same directory. Such as images, text files etc. Thus, in case you are using some plugin or theme which is old or vulnerable, any hacker can easily know about them. Therefore, it is a good idea to disable directory browsing unless and until you don’t need it deliberately to show some content.

WordPress htaccess-directory-listing -min

Disable Index or Directory browsing in WordPress without any plugin

We can stop listing of files in WordPress without any plugin, what we need is only the access of .htaccess file.

  1. Go to your hosting Cpanel.
  2. Open File Manager.
  3. Click on the Public_html folder or where ever you have your website WordPress files.
  4. Select the .htaccess file and click on the Edit button given on the top.

    edit htaccess file to stop listing of files wordpress
  5. In the .htaccess file scroll down to the bottom and simply add this line:

    Options -Indexes
  6. Click on the Save Changes button given on the top right side.
  7. Now again try to list the index files or directory of WordPress in the web browser, however, this time you will get a message that the page has been deleted or move with 404 output.

Stop directory listing in WordPress using Yoast SEO

If you already a user of popular Yoast Plugin then you don’t have to look for any other plugin or CPanel. Just click on Yoast SEO option given on the left side in the WordPress Admin Dashboard.

Stop-directory-browsing-lisitng-on-WordPress-using-Yoast-SEO-2

Click the File Editor to quickly edit files such as robots.txt and .htaccess files.

Yoast-SEO-htaccess-file-editor

Now, simply go to .htaccess section and scroll down to the end, where just paste this value: Options -Indexes

htaccesss listing of files on wordpress disable

Hit the Save Changes to .htaccess button.