{{announcement.body}}
{{announcement.title}}

To C, or Not to C

DZone 's Guide to

To C, or Not to C

If you've ever had to configure Apache you've likely had to deal with httpd.conf files. Ever wonder why some IfModule constructs have a .c but others don't? Read on to find out more.

· Web Dev Zone ·
Free Resource

I've edited httpd.conf files for years now, and hadn't given much thought to why some “IfModule” constructs have a .c and some don’t. But then, I was editing a config and it was a mix of .c and non-.c constructs, so it niggled me as to why.

Consider the following:

LoadModule headers_module modules/mod_headers.so

This is split into two parts:

  • Module Identifier – headers_module – This is the module name. If in doubt, Google the module and get the name from the documentation.
  • Source File – mod_headers.c – This is the file name with a c extension.

We can then look at the “IfModule” documentation which gives the syntax:

<IfModule [!]module-file|module-identifier> ... </IfModule>

Putting this together we can use either the module identifier (headers_module):

<IfModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
</IfModule>

Or the source file (mod_headers.c):

<IfModule headers_module>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
</IfModule>

Which Is Better?

None are better—the best option is to choose one approach and stick to it. I prefer the module-file name as it is easier to reconcile to my modules directory.

References

http://httpd.apache.org/docs/current/mod/mod_headers.html

http://httpd.apache.org/docs/2.4/mod/core.html#ifmodule

Topics:
directory ,config ,modules ,apache ,conf

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}