mod_headers module does not load, though it's enabled in httpd.conf

Tomáš Zato - Reinstate Monica picture Tomáš Zato - Reinstate Monica · Jan 22, 2014 · Viewed 11.1k times · Source

I need mod_headers to force download of a file depending on GET parameter.

  <FilesMatch "*.gif">
     <If "%{QUERY_STRING} =~ /dl/">
        #Download header
        Header set Content-Disposition "attachment"
     </If>
  </FilesMatch>

Code above produces an error 500. However, if I wrap it properly in <IfModule>, it does not do anything at all:

<IfModule mod_headers>
  <FilesMatch "*.gif">
     <If "%{QUERY_STRING} =~ /dl/">
        Header set Content-Disposition "attachment"
     </If>
  </FilesMatch>
</IfModule>

This makes me think that mod_headers didn't load at all. But I have it enabled in httpd.conf:

...
LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
#LoadModule heartbeat_module modules/mod_heartbeat.so
...

Is there any debug log to find out what mods have been loaded and what not?

Answer

Jon Lin picture Jon Lin · Jan 23, 2014

You need to check for the mod_headers.c module:

<IfModule mod_headers.c>

(See this answer about the .so/.c stuff)

But the reason you're getting the 500 error is twofold.

First, the <FilesMatch> container expects a regular expression, and "*.gif" isn't a valid regular expression. You probably just want to use the <Files> container.

Second, the <If> isn't available in apache 2.2, only version 2.4. If you aren't using apache 2.4, then you're not going to be able to use the <If> container.