About
mod_header is a apache module that permits to set HTTP header.
Articles Related
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
- the cache-control header
- and the cors header Access-Control-Allow-Origin
<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