Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration
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
Header set Content-Disposition attachment
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 service apache2 restart
Simple as that. No other configurations are necessary. This will fix your Invalid command ‘Header’ issues.