Apache - HTTP Header (mod_header module)

Card Puncher Data Processing

About

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

Example

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"
    </FilesMatch>

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

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"
    </LocationMatch>
</VirtualHost>

You need to restart when you change a virtual host configuration

Load

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

LoadModule headers_module modules/mod_headers.so

Documentation





Discover More
Card Puncher Data Processing
Apache - Module

A module is handler (plugin) to the apache server They are in the modules directory and can be loaded with the LoadModule command in the conf file. Example: To list all modules, execute...
Hsts Chrome Message
HTTP - Strict Transport Security (HSTS) - mandatory HTTPS

Strict Transport Security (HSTS) is a header that tells the client that the website should always be contacted with HTTPS When HSTS is on, if it's not possible to make a https connection (for instance...
Http Headers Firefox
HTTP - Header (Fields)

Headers are : properties (textual name-value pairs, ie both name and value are text) located in the head of: a http request that the client sends a http response that the server sends The HTTP...
Card Puncher Data Processing
The Apache htaccess file

The Apache htaccess file permits to set a configuration based on the directory layout of your website
The Cache-Control HTTP header

The cache control header is the most important header in the HTTP cache mechanism and permits to turn it on or off alongside other properties.



Share this page:
Follow us:
Task Runner