Over a million developers have joined DZone.

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

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
directory ,config ,modules ,apache ,conf

Published at DZone with permission of Martin Farrell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}