Htaccess für Apache 2.2

<Files "*">
 AuthType Basic
 AuthName "Authentication Required"
 # to be explicit, state the provider
 AuthBasicProvider file
 AuthUserFile "/etc/httpd/.htpasswd"
 Require valid-user
</Files>

# Allow external access to piwik.php and piwik.js and matomo.js and robots.txt
<FilesMatch "(^piwik\.(php|js)|^matomo\.(php|js)|robots\.txt|optOut.js)">
 Require all granted
</FilesMatch>

# Allow Opt-Out
<Files "index.php">
 <If "(%{QUERY_STRING} =~ /^module\=CoreAdminHome\&action\=optOut(?!.*module\=)(?!.*action\=)/)">
   Require all granted
 </If>
</Files>

P.S. Die Variante ist für apache2 >= 2.4, aber 2.2 solltest du sowieso nicht mehr verwenden!