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>