This article shows how to edit the HTTP headers that Apache sends to a client directly.

Modifying HTTP headers

The mod_headers module is included in the Apache setup on HostGinger Hosting servers. This means that using the Header directive in an .htaccess file, you may quickly add, alter, and delete HTTP response headers.

Adding a header

Use the set or append options to add a custom header to the HTTP response headers. The set option replaces any heading with the same name with the supplied header. If the header does not already exist, the append option creates it. However, if the header already exists, the append option adds to the existing header value.

For example, the following sample configuration demonstrates how to set a header and append to a header:

<IfModule mod_headers.c>
  Header set Animal cow
  Header set Animal monkey
  Header append Animal camel
</IfModule>

In this example, the Animal header is first set to cow. But because the next header option is also set, the Animal header is reset to monkey. Lastly, camel is appended to the Animal header. This generates an HTTP response header that resembles the following:

HTTP/1.1 200 OK
Date: Tue, 24 Jun 2014 15:23:33 GMT
Server: Apache
Animal: monkey, camel
Editing a header

To edit a header, use the edit option. With the edit option, you can use regular expressions to do search-and-replace operations on header values.

For example, the following sample configuration demonstrates how to do a (very) simple search-and-replace operation on a header:

<IfModule mod_headers.c>
  Header set Animal monkey 
  Header append Animal camel
  Header edit Animal "camel" "llama"
</IfModule>

In this example, camel is replaced by llama. This generates an HTTP response header that resembles the following:

HTTP/1.1 200 OK
Date: Tue, 24 Jun 2014 15:42:21 GMT
Server: Apache
Animal: monkey, llama
Removing a header

To completely remove a header from an HTTP response, use the unset option.

The following sample configuration demonstrates how to remove a header:

<IfModule mod_headers.c>
  Header unset Animal
</IfModule>
Was this answer helpful? 0 Users Found This Useful (0 Votes) htaccess file, htaccess rule, HTTP headers