Also tried the following:
<Directory /var/www/>
<If "%{REMOTE_ADDR} != '127.0.0.1'">
AuthType Basic
AuthName "Development Environment"
AuthUserFile /var/www/files/.htpasswd
require valid-user
</If>
</Directory>
Which looks very similar to User:Andrujhon's solution. Just that it is done in apache conf instead of LocalSettings.php
.