User Tools

This is an old revision of the document!


Writing /var/www/html/wiki.freefm.uk/data/log/deprecated/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed
Writing /var/www/html/wiki.freefm.uk/data/log/error/2026-02-04.log failed

Password protecting your site with an .htaccess file

Source: External Link

Step 1 — Create the .htpasswd file

In Linux shell navigate into the directory you wish to password protect.

Run pwd to confirm the full file path to this directory. You’ll need this full path in the next step.

[server]$ pwd
/home/username/example.com

Create an .htpasswd file by running the following command in the directory you wish to password protect. This uses the htpasswd utility and the full path to the directory. For example, if the username you’re creating to log in is user1, run the following:

[server]$ htpasswd -c /home/username/example.com/.htpasswd user1

Enter a password for the new user named user1. The code in your .htpasswd file then displays the encrypted password like this:

nano ./htpasswd
user1:$apr1$bkS4zPQl$SyGLA9oP75L5uM5GHpe9A2

     Run it again (without the -c option) for any other users you wish to allow access to your directory.
     

Confirm the permissions are set to 644 by running the following command.

[server]$ chmod 644 .htpasswd

Step 2 — Create the .htaccess file

      Make sure to add this .htaccess file in the same directory you added the .htpasswd file.
      

[server]$ nano .htaccess

Code examples to add to the .htaccess file Protect an entire website This example password protects an entire website by placing the files in the site’s main web directory.

      Make sure to change the highlighted lines to your username, domain name, and specific file names.
      

#Protect Directory
AuthName "Dialog prompt"
AuthType Basic
AuthUserFile /home/username/example.com/.htpasswd
Require valid-user

Protect a single file This example password protects a single file named admin.php:

#Protect single file
<Files admin.php>
AuthName "Dialog prompt"
AuthType Basic
AuthUserFile /home/username/example.com/.htpasswd
Require valid-user
</Files><code>

Protect multiple files
This example protects multiple files such as admin.php and staff.php.

<code>#Protect multiple files
<FilesMatch "^(admin|staff).php$">
AuthName "Dialog prompt"
AuthType Basic
AuthUserFile /home/username/example.com/.htpasswd
Require valid-user
</FilesMatch>

Rest can read on https://help.dreamhost.com/hc/en-us/articles/216363187-Password-protecting-your-site-with-an-htaccess-file