Magento – How to secure Magento 2 dev site using .htaccess

.htaccessmagento2

Previously using Magento 1 I have been able to secure dev sites easily using a .htaccess / .htpasswd setup. It's just to keep the site from being viewed before it's ready. However the same setup in Magento 2 seems to have problems.

After entering the password prompt triggered by the .htaccess I can login to the Magento 2 admin but it then shows an error 'Something went wrong' and nothing will work after that. Everything works fine without the .htaccess code in place.

Any suggestions how to avoid this error using .htaccess. I only need to use it to password protect the front end so even a solution to exclude the admin url would work.

This is the code I'm using in the .htaccess file, put right at the end of the file.

AuthUserFile /home/site/public_html/.htpasswd
AuthName "Username and password required"
AuthType Basic
Require valid-user
<Limit GET POST>
  Require valid-user
</Limit>

Best Answer

I didn't understand your question completely, But you can enable .htaccess password-protection using below way.

.htaccess

AuthType Basic
AuthName "My Protected Area"
AuthUserFile /path/to/magento/.htpasswd
Require valid-user

.htpasswd

user:$apr1$FjTWStRX$6vA1nzhbpWsuxw4pkUcC11

Above is worked for me.

Related Topic