Apache - HTTP Header (mod_header module)


mod_header is a apache module that permits to set HTTP header.


Matching on file name (in htaccess)

If you add the below code snippet in your htaccess file, you will set the following response header

<IfModule mod_headers.c>
    # WEEK
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
        Header set Cache-Control "max-age=604800, public"

    # WEEK
    <FilesMatch "\.(js|css|swf)$">
        Header set Cache-Control "max-age=604800"
    Header set Access-Control-Allow-Origin "https://fiddle.jshell.net"

Matching on URL path in Virtual host

Matching on path in a virtual host conf with the locationmatch directive

All path that starts with /lib/tpl/strap/

<VirtualHost *:80>
    ServerName myhostname
    <LocationMatch "^/lib/tpl/strap/">
        Header set Cache-Control "max-age=604800, public"

You need to restart when you change a virtual host configuration


In Apache - Configuration (httpd.conf), you can load the module with:

LoadModule headers_module modules/mod_headers.so


Powered by ComboStrap