Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

Posted by on February 1, 2013 in Apache, Web Servers | 0 comments

So I had an old script that created the .htaccess file for a folder that I wanted to force all files to download instead of rendering, or processing however they normally would. The script for that file can be done in any language, but the .htaccess contents are as follows

<Files *.*>ForceType application/octet-stream
Header set Content-Disposition attachment</Files>

It’s pretty self explanatory. Notice the Files *.* part. That means any file. You can change that to other things like *.txt if you want only txt files to be downloaded, but normal operations for every other extension. The general premise is that it overrides the normal functionality and forces a download of the file. Problem is, when I ran this on a page, it gave me the following error:

Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

Simply put, Header is a command of sorts in the Apache configuration. Just like Linux, commands have to be installed before they’re used. Because I had never run a script like this on that server, Apache didn’t know what Header was. Simply enable the headers mod and you’re all set. Run the following code if you’re having troubles.

sudo a2enmod headers
sudo service apache2 restart

Simple as that. No other configurations are necessary. This will fix your Invalid command ‘Header’ issues.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>