HTTP Headers
Location
The HTTP Location
response header indicates the URL to which a page should redirect. It is meaningful primarily when used with a 3XX
redirection response or a 201 Created
status response.
During redirections, the HTTP method used in the subsequent request to fetch the redirected resource depends on the original method and the type of redirection:
303 See Other
responses always result in aGET
request after redirection.307 Temporary Redirect
and308 Permanent Redirect
maintain the same method as the initial request.301 Moved Permanently
and302 Found
are supposed to use the same method as the original request, although some older user agents might not follow this strictly.
All these responses include a Location
header indicating the redirect destination.
In scenarios involving resource creation, the Location
header provides the URL of the newly created resource so clients can access it directly.
The Location
and Content-Location
headers are different. The Content-Location
indicates the URL for future direct access to the resource, especially after content negotiation. The Location
header is associated with the response, whereas Content-Location
relates to the specific resource representation returned.
Syntax
Location: <url>
Directives
- <url>
- May be relative to the request URL or an absolute URL.
Example
Location: /index.html
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Location header.
This is especially useful for testing how your application handles redirects during development or debugging. Steps to Modify the Location Header:
- Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
- Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
- Add a new header modification:
- Under “Action”, select “Add” or “Override”.
- In the “Header Name” field, enter Location.
- In the “Header Value” field, enter the new URL to which you want the redirects to point (e.g., https://example.com/new-path).
- Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
- Save the rule.
Once set up, Requestly will modify the Location header in all matching responses, letting you test how your application behaves with redirected URLs, which is helpful for debugging and verifying redirect flows. Sometimes you need to modify the Location header to test how your app handles redirects or to simulate different redirect URLs without changing the backend. This makes it easier to debug or try new redirect scenarios quickly.
Table of Contents
- No headings found.