Social Media

To c or not to c

Ive edited httpd.conf files for years now, and hadnt 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 –
[sourcecode]LoadModule headers_module modules/mod_headers.so[/sourcecode]

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 –
[sourcecode] <IfModule [!]module-file|module-identifier> … </IfModule>
[/sourcecode]

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

[sourcecode] <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>
[/sourcecode]

Or the source file(mod_headers.c) –

[sourcecode] <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>
[/sourcecode]

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

About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: