'htpasswd coflicting with htaccess [duplicate]

When I try to add AuthType my site does not work when I enter my password. Do you know what is wrong?

I am getting error 500. But without AuthType it works

AuthType Basic
AuthName "restricted area"
AuthUserFile .htpasswd
require valid-user

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options All -Indexes -MultiViews

RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ $1\.html

RewriteCond %{REQUEST_URI} ^$1/index [NC]
RewriteRule ^ - [L]

RewriteRule ^en/ - [L]
RewriteRule ^pl/ - [L]

RewriteCond %{HTTP:Accept-Language} !^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /en%{REQUEST_URI} [L]

RewriteCond %{HTTP:Accept-Language} ^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /pl%{REQUEST_URI} [L]


Solution 1:[1]

Reference https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype

AuthType can only be enclosed in a <Directory> statement, or in a .htaccess file. So you must specify a directory, like this:

<Directory "/www/htdocs">

    YOUR AUTH CONFIGURATION HERE

</Directory>

It is not allowed to have it like you did. If you want to protect your entire site with this, you can setup your <Directory> clause on the same directory as your DocumentRoot value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nic3500