6

My .htaccess file was working last year, and as far as I know I had not changed it. However, I am now getting the following error:

AuthType not allowed here

My .htaccess file looks like this:

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /pwd/.htpasswd
Require valid-user

In case it helps my main apache .conf file for this domain looks like this:

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName subdomain.example.com

  DirectoryIndex index.html index.php
  DocumentRoot /var/sites/example.com/subdomain

  LogLevel warn
  ErrorLog /var/sites/example.com/log/error.log
  CustomLog /var/sites/example.com/log/access.log combined
</VirtualHost>

Any ideas what the problem could be?

1 Answer 1

5

AuthType (and other directives) not being allowed "here" is almost certainly a missing AllowOverride allowing .htaccess files to override the directive(s).

https://httpd.apache.org/docs/current/mod/core.html#allowoverride

AllowOverride only goes in <Directory> sections. The solution might look something like this:

<Directory "/var/sites/example.com/subdomain">
    AllowOverride All
</Directory>

which would allow .htaccess overrides only in the /var/sites/example.com/subdomain directory.

A <Directory> directive will already exist and you may wish to modify it rather than add a new one. This search help locate it on most Linux systems:

grep -r "Directory" /etc/httpd/ 
Sign up to request clarification or add additional context in comments.

4 Comments

This works just fine but you could also use Authconfigthat seems more secure than All. I've submitted a review.
@LouisLoudogTrottier Noted that you can be more specific with AllowOverride.
The httpd service also ned to be restarted for the change to take effect. systemctl restart httpd ;)
@LouisLoudogTrottier That is true about the restart (ideally, do a "graceful" restart: apachectl -k graceful or httpd -k graceful). Your systemctl example would not work on my system(s). :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.