How to Password Protect a Single File
Step One: Edit .htaccess
If you haven't already done so, first, open your text editor and create a file named .htaccess.
Add the following lines into the .htaccess file where MYFILE.html is the name of the file you want to protect and APPNAME is the name of your app.
<Files MYFILE.html> AuthType Basic AuthName "Authentication Required" AuthUserFile /srv/users/serverpilot/apps/APPNAME/public/.htpasswd Require valid-user </Files>
Step Two: Create .htpasswd
Next, SSH in to your server as the serverpilot user (or the system user the app belongs to). Run the following command to create your .htpasswd file, replacing APPNAME with the name of your app.)
Step Three: Assign Username and Password
Now, use the htpasswd-sp command to add or change a password for a user yourname. (You can substitute any username for yourname).
htpasswd-sp ~/apps/APPNAME/public/.htpasswd yourname
Follow the prompts in the command line to add the new password.
When you visit the file through your browser, you'll now be prompted for a username and password.