There are several answers but there a number of things wrong with this question and I would like to address these:
- If you get an error (e.g. 500), look in the log files (if you have access to them). e.g.
/var/log/apache2/ssl_error.log
e.g.
cat /var/log/apache2/ssl_error.log
[Tue Jun 01 19:05:34 2021] [alert] [pid 31154] config.c(2119):
[client *******] /var/www/mysite/public/tmp/.htaccess:
<Directory not allowed here [lid YLZo3quRlv2EKOAABVoFLwAAAIM]
- Putting
AllowOverrides
in a .htaccess makes no sense and is not allowed. See Context. See also my explanation below. It should be defined in the Apache configuration (e.g. /etc/apache2
)
- Allowing everything is usually not the best idea. Be as restrictive as possible!
- the
Directory
directive is missing a directory, should be e.g. <Directory /var/www/html/etc>
- the
Directory
directive does not make sense in an .htaccess
. The location of the .htaccess
in a directory already has the effect of making the statements within apply to a specific directory
- do not mix and match snippets that are intended to be put in the Apache configuration (e.g. in
/etc/apache2/...
) with statements that are intended to be put in .htaccess
- though most of the time, they will be identical, there are some subtle differences
- If you have the possibility to modify the Apache configuration directly, do not use
.htaccess
and deactivate it. (for performance reasons, among others. Also you can have all configuration in one place, put it in version control or manage it via a software configuration management tool, e.g. Puppet, Ansible, SaltStack)
Unless you really cannot access and modify the Apache configuration directly, you do not need .htaccess
. This is a common misconception.
That you saw a 500 error proves my point. If you change configuration in the Apache configuration directly (and not in .htaccess), you will usually get an error message with an explanation and information about the error and the line number (e.g. when you do service apache2 reload
or apachectl configtest
).
Also, look in the documentation. It is really quite good. For most directives, you can find where they apply (see "Context").
For example, for IfModule, you can see:
Context: server config, virtual host, directory, .htaccess
For, AllowOverrides it is:
Context: directory
Note the missing .htaccess in the Context!
Instead of googling for information which repeat the same mistakes over and over, look in the documentation!
Docs
<Directory>
directive requires a path argument. – FKEinternet