How to block a directory with .htaccess?


by vinnie , in category: SEO , 8 months ago

How to block a directory with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer


by drew , 8 months ago


To block a directory with .htaccess, follow these steps:

  1. Create or locate the .htaccess file in the parent directory of the directory you want to block.
  2. Open the .htaccess file using a text editor.
  3. Add the following lines of code to the .htaccess file:
Options -Indexes

This code will prevent directory listing.

Deny from all

This code will deny access to the directory.

  1. Save the .htaccess file.
  2. Verify that the directory is now blocked by accessing it in a web browser. You should receive a "403 Forbidden" error message.

Note: Make sure you have access to the server's configuration files or have the AllowOverride directive set to "All" in the server configuration. Otherwise, .htaccess files may be ignored.