Do you want to protect at specific directory with password and redirect any one file like index.php or test.php use .htaccess

The below exmaple explore in Linux system,

# cd /home/username/public/

Create a  .htaccess file at particular directory add below coding :

RewriteEngine on
AuthType Basic
AuthName "restricted area"
AuthUserFile /home/username/public/.htpasswd
require valid-user
DirectoryIndex test.php


Then create a .htpasswd file and add encrypted password,

user:sk904SYSak0laA


RewriteEngine    : Redirect path or file

AuthType            : Type of user authentication

AuthName         : Authorization realm for use in HTTP authentication

AuthUserFile      : Its tell information to Apache where the .htpasswd file is going to be located

DirectoryIndex  : specify a default page to display when password authenticated or accessed (test.php)