Location Header
Table of Content
The Location header is an HTTP response header used to redirect the client to a specific URL. It often accompanies a 3XX HTTP status code, indicating a redirection. This header essentially tells the client where the requested resource has been moved. Aside from redirection, it can be used to indicate the URL where a newly created resource is located.
Syntax
HTTP/1.1 3XX Object moved
Location: http://www.example.com
Directives
The Location header does not have any directives. It contains the URL of a redirect target or newly created resource.
Examples
In case of redirection.
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/newpage
For a new resource.
HTTP/1.1 201 Created
Location: https://www.example.com/newpage/1
Browser Compatibility
Browser | Compatibility |
---|---|
Chrome | Supported |
Firefox | Supported |
Safari | Supported |
Opera | Supported |
Edge | Supported |
How to modify Location header
ModHeader is a Chrome extension which can be used to modify HTTP request and response headers. With ModHeader, you can add, modify, and remove headers that control browser behaviour, including the Location header.
Here is a simple example:
- Open ModHeader, click on 'Add' button on Request Headers.
- In the 'Name' field, enter 'Location'.
- In the 'Value' field, enter the URL you wish to set, for example 'https://www.example.com/newpage'.
- Now whenever your browser makes an HTTP request, it will include this new Location header.
This ability to modify the Location header can be helpful for testing how your application responds to different redirect scenarios without needing to modify server-side code.