How do I get Apache2 to parse (without error) Header directives in a .htaccess?
Solution 1
With apache2, just run a2enmod headers
and then sudo service apache2 restart
and it will install the headers module automatically.
Solution 2
You'll need to add a line like:
LoadModule headers_module modules/mod_headers.so
To your httpd.conf
to add support for that. In Ubuntu and similar, you can do a2enmod headers
and it'll automatically enable it in your configuration.
Related videos on Youtube
Christos Hayward
Jonathan Hayward is a recovering geek. He holds master's degrees bridging math and computer science (UIUC) and philosophy and theology (Cambridge), and is considered to be in the profoundly gifted range. He is presently learning Node and Russian. Read full biography—it's interesting.
Updated on September 18, 2022Comments
-
Christos Hayward over 1 year
I am getting pages loading with a 500 internal server error, due I believe to a directive that Apache has not been configured to allow.
I have AllowOverride set to all, and a .htaccess file, including:
<FilesMatch "\.(eot|ico|pdf|flv|jpg|jpeg|png|gif|svg|swf|ttf|woff)$"> Header set Cache-Control "max-age=31536000, public" Header set Expires "Wed, 23 Apr 2014 17:00:01 UTC" </FilesMatch>
/var/log/apache2/error.log has:
[Sat Jul 20 15:12:36 2013] [alert] [client 24.15.83.241] /home/jonathan/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
What do I need to specify so that Apache2 will properly handle the 'Header' directive?
-
Himanshu Mishra over 8 yearsThis answer should be accepted
-
Neurotransmitter over 8 yearsIndeed this answer is the best, however I dare to say that some modern GNU/Linux distros (like the latest Debian) are based on
systemd
and have a different syntax on managing services. Restart Apache:sudo systemctl restart apache2.service
. However, as of now a fallback function exists and thus the oldsudo service
command does work. But it may stop working in the nearest future. -
Michael Hoffmann over 5 years
a2enmod
is in/usr/sbin
on my system. That's not in my non-sudoer user's PATH, so a2enmod isn't discoverable unless you're root. TL;DR: runsudo a2enmod
instead of justa2enmod
.