If you want to have more control over who reaches your website's content, you can implement a login form. This way, a password will be required to provide access to your website or parts of it.
Let’s go through different ways how it can be achieved:
Option 1 – Password Protect Directories
One of the easiest ways is to enable the Password Protect Directories feature for your website.
This option allows you to protect all of your website or just one directory without the need to edit any code 😊
Option 2 – WordPress Plugin
If your website is WordPress-based, you can use a plugin such as WordFence to enable two-factor authentication (2FA) or add a captcha feature to prevent bots from attempting to log in to your website.
There are other plugins that can help you limit access to registered users only, such as Force Login.
Option 3 – .htaccess
If you feel comfortable coding, you can add the login form by a .htaccess file in the directory you want to protect.
First, check if the directory you want to protect has a .htaccess file, or you can create one if needed. For example, to protect your complete website, place it in the public_html folder.
You will also need to create a file named .htpasswd that can be anywhere on your account. For safety reasons, it is recommended that the .htaccess and .htpasswd files be stored in different folders.
Once you have created the .htpasswd file, add to it the following line:
password with your desired values.
Go back to the .htaccess file and insert these lines:
AuthName "Authorization required"
/path/to/.htpasswd is the actual path where the .htpasswd file will be located. For your Hostinger account, if the file is inside a subfolder of your domain, it would look similar to this:
That's it! Your website will be password protected 😊