How to block a directory with .htaccess?

Member

by vinnie , in category: SEO , 8 months ago

How to block a directory with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by drew , 8 months ago

@vinnie 

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:
1
Options -Indexes


This code will prevent directory listing.

1
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.