🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Location

HTTP Header

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 a GET request after redirection.
  • 307 Temporary Redirect and 308 Permanent Redirect maintain the same method as the initial request.
  • 301 Moved Permanently and 302 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

http
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:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. 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).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. 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.