Published using Google Docs
How to define HTTP Header specification for a website on Apache Server
Updated automatically every 5 minutes

How to define HTTP Header specification for a website on Apache Server?

1) Download and Run UwAmp server.

2) Apache Config Window

3) Write Header Specification in .htaccess file

4) Test

This tutorial shows how to define the HTTP Header specification for a website on Apache Server.

We will be using a portable web server uwamp as it provides a visual interface to access the Apache Module Settings.

Then, we look for the Apache Config file containing the settings.

Finally we write and save the specification in .htaccess file for our chosen website path.

1) Download and Run UwAmp server.

UwAmp server is just to help us find the Apache Module Settings quickly. It is really useful for beginners who are struggling to understand so many aspects of a web server.

Download the application from http://www.uwamp.com/en/?page=download or from here.

When you run, you should get a user interface as follows. You should notice the Apache Config button. Click on the button.

2) Apache Config Window

Apache Config window consists of two tabs; Virtual Server and Modules.

Select Modules tab.

Scroll down until you see the item headers_module. Select the item.

Close the window.

where is it (module setting value) actually saved?

Click on the Code button besides the Apache Config button.

The setting value is actually stored in a file ‘httpd.conf’ (in UwAmp, it is stored as httpd_uwamp.conf’.

So, next time, if you want to enable headers_module, search for the file ‘httpd.conf’ and delete the symbol ‘#’ prefix.

3) Write Header Specification in .htaccess file

We put the .htaccess file into a folder that we would want to enforce our specification.

Assuming we have a folder ‘test’ under localhost which we want to enforce our specification, we would do as follows.

codes:

# Cross domain access

Header add Access-Control-Allow-Origin "*"

Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"

Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

Run the server and browse the url http://localhost/test 

4) Test

Let’s see what happen when we disable the module.

Go back to UwAmp window and disable the headers_module item.

The server should restart automatically.

Browse the url and see the outcome.

Here, we see that when the headers_module is disabled, the server will return the error message:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at contact@exemple.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.


Apache/2.4.10 (Win32) OpenSSL/1.0.1h PHP/5.4.31 Server at localhost Port 80

 

The server also explains more in the server error log file.

Let’s look at the file.

Go to UwAmp window and look at the Tools Section. There is a small drop-down button. Click it and select show Apache error logs.

The file will be automatically opened by the default text editor.

The log gives us sufficient evidence that the error comes from our .htaccess which contains an invalid command. In our case, the command is not recognized because the related module is not included in the server configuration.

C:/Web/UwAmp/www/test/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

Select the headers_module again and you should get back the initial output.