.htaccess maker

.htaccess generator maker easier

Folder password protection using htaccess

With htaccess it becomes very easy to protect a folder or directory and this method is simply referred to as “htaccess authentication”. In order to protect your folder password with htaccess , you need to upload two files; .htaccess and .htpassword within the directory in which you want to password-protect, if you have not these files on your server, you can create new ones using Notepad just make a new file and save it without name just .htaccess extension, and set file type as All Files as the following image.

htaccess file

In order to use htaccess to protect a folder password , you need to use the following commands;

AuthType Basic
AuthName “Password Protected Area”
AuthUserFile /path/to/.htpassword
Require valid-user

All these components are already in the htaccess file and all you need to do is to change the path/to/.htpassword/ and choose the password you want to use. The next step is to upload the .htpassword file that contains both the username and password and then you can enter the password protected file. You may need to use a password generator to create another password for the file but you must keep in mind that each line of the .htpassword command will have a different combination of username and password.

Your .htaccess File

Download Copy

You can create the .htaccess file using a good text editor like TextPad, UltraEdit and Microsoft WordPad. You cannot use Microsoft NotePad. An .htaccess file can contain a single or multiple lines depending upon the functions you want to include in it. You will need to use an FTP (File Transfer Protocol) program to upload the file. Also you must to upload the file in “ASCII” mode. Some FTP programs use “BINARY” as the default to upload files. If that’s the case you must change it to “ASCII”. Upload the file to the directory you want it to reside in. when you look at the files in your website’s directory you might not see it as your web server’s software is probably hiding it.

Password protect file/folder (requires .htpasswd file)

Htaccess Prevent directory listings or enable folder listing

Using htaccess to prevent directory listings can be helpful in so many ways, if you have key directories with important zips, and archive files or you simply want to prevent others from viewing your image directories.

In order to disable directory listings, simply create .htaccess file and put the following instruction in it, it will block folder listing.

IndexIgnore *

This command line will instruct the server to disable the directory listings and all those files within the directories that contain .htaccess file. The * symbol in the command line will simply prevent the directory from displaying any file .

It is possible to use htaccess to prevent or disable the display of some specific types of files, if you want to disable the display of zip files for instance, simply create the .htaccess file, and use the following code line in it

IndexIgnore *.zip

Another example, if you want only to hie images of the type JPG, GIF or PNG you can use the same instruction as the following

IndexIgnore *.jpg *.gif *.png

On the other hand, if your server is preventing listing folders by default and you want to enable it you can use the following piece of code

Options +I

Your .htaccess File

Download Copy

You can create the .htaccess file using a good text editor like TextPad, UltraEdit and Microsoft WordPad. You cannot use Microsoft NotePad. An .htaccess file can contain a single or multiple lines depending upon the functions you want to include in it. You will need to use an FTP (File Transfer Protocol) program to upload the file. Also you must to upload the file in “ASCII” mode. Some FTP programs use “BINARY” as the default to upload files. If that’s the case you must change it to “ASCII”. Upload the file to the directory you want it to reside in. when you look at the files in your website’s directory you might not see it as your web server’s software is probably hiding it.

Prevent Directory Listing

Block access to Directory Listing

Copyright © 2021 · htaccessmaker.com · Log in