Apache Tip : Add a Custom HTTP Response Header

Here’s a handy tip for adding a custom header of your design to every response.

Open your Apache config file (name is usually httpd.conf), usually found in one of these locations (depending on your distro):


Tip: You can also discover the location of this file by executing one of the following:

apache2 -V

or (depending upon your distro):

httpd -V

To find httpd (or apache2, or any other program), use this:

locate httpd

Anyway, to add a header of your choosing to each response, add the following to your config file:

<IfModule mod_headers.c>
        Header set MyHeader "%D %t"

In the example above, a custom response header named MyHeader is sent along with the value of the current date (%D) and time (%t).

Author: Alex T. Silverstein

A developer who wants to help you and himself by writing down good tidbits for free

3 thoughts on “Apache Tip : Add a Custom HTTP Response Header”

  1. Thanks for the information. It was very useful. Do you know if i can add Host Name where Apache is installed as a part of the response header ?

  2. Hi,

    I was trying to add the host name to the response header using “%{HOSTNAME}e”. But the response was null. Can you please help

Leave a Reply

Your email address will not be published. Required fields are marked *