Securing installation via .htpasswd

It seems there isn’t an easy answer to this, however I have got this working by adding the following to the .htaccess file:

    SetEnvIf Request_URI "^/guest/view/invoice/.*$" GUEST
    SetEnvIf Request_URI "^/index.php/guest/view/invoice.*$" GUEST
    
    SetEnvIf Request_URI "^/guest/view/generate_invoice_pdf/.*$" GUEST
    SetEnvIf Request_URI "^/index.php/guest/view/generate_invoice_pdf/.*$" GUEST
    
    SetEnvIf Request_URI "^/guest/payment_handler/make_payment/.*$" GUEST
    SetEnvIf Request_URI "^/index.php/guest/payment_handler/make_payment/.*$" GUEST
    
    SetEnvIf Request_URI "^/uploads.*$" GUEST
    SetEnvIf Request_URI "^/assets.*$" GUEST
 
    # https://stackoverflow.com/a/10128290
    SetEnvIf REDIRECT_GUEST (.+) GUEST=$1
 
    AuthType Basic
    AuthName "Admins Only"
    # Edit the following line to the location of your htpasswd file 
    AuthUserFile /var/www/.htpasswd
    Require valid-user
    Satisfy    any
    Order      deny,allow
    Deny from  all
    Allow from env=GUEST
1 Like