What Does the Content-Location Header Say About a URL?

Learn what the Content-Location header says about a URL, how it differs from Location and canonical links, and how to compare responses locally.

Published
Reading time
6 min read
What Does the Content-Location Header Say About a URL?
On this page

The Content-Location header meaning is that a server associates the representation in a response with a particular URI. That URI can differ from the URL the client requested, but it is not an instruction to redirect.

This article explains how to interpret the header, how it differs from related URL signals, and how to inspect it in a local example. The current HTTP semantics specification could not be consulted in this environment, so check it for normative details before using this article as a protocol reference. The example code was not executed here.

Key Takeaways

  • Content-Location identifies a URI associated with the enclosed representation; it does not change the request target.
  • A different Content-Location can indicate that the same representation is available at a more specific URI, such as a language-specific URL.
  • Unlike Location, it is not a redirect destination. Unlike an HTML canonical link, it describes an HTTP representation rather than a preferred page for indexing.
  • The header is a server claim, not proof that another request will return identical bytes or that the referenced URL is safe to fetch.

How to read Content-Location

Consider a request for /report that returns an English representation and includes:

Content-Location: /report.en

The request target remains /report. The header associates the returned representation with /report.en. Because the value is a relative URI reference, a client resolves it against the request's target URI. For example, if the target is https://example.test/report, the resolved URI is https://example.test/report.en.

When a successful GET response names a different URI, the server is effectively claiming that a GET of that URI would have returned the same representation at the time the response was generated. That is useful for identifying a more specific representation, but it is not a promise about future requests: the resource can change, and authentication, negotiation, intermediaries, or server behavior can affect what a later request returns.

If the header instead identifies the request target, it associates the response representation with that target. Interpret the field in the context of the method and status: a response without representation content, such as a 204, does not supply a body to compare. A partial-content response also requires care; a returned range is not necessarily the entire representation.

Advertisement

SignalWhat it identifiesWhat to do with it
Request targetThe URI the client is asking the server to act on.Interpret the response in the context of that request.
Content-LocationA URI associated with the response representation.Treat it as representation metadata, not a redirect instruction.
LocationA URI whose role depends on the response status; for example, a redirect destination or a newly created resource.Interpret it alongside the status code and method.
HTML <link rel="canonical">An author's preferred canonical URL for the page, commonly used by search engines.Treat it as a canonicalization signal, not an HTTP redirect or proof of identical representations.

For example, a 201 Created response can use Location to identify a created resource. If it also has Content-Location, that field concerns the representation in the response; do not assume the two fields have interchangeable meanings. An HTML canonical link, meanwhile, appears in document markup and may point to a preferred page even when the bytes or URLs differ.

Inspect and compare a representation locally

This example uses Python 3 and curl. The local server deliberately serves the same bytes from two paths and adds Content-Location only to the /report response. It does not perform language negotiation or redirect requests.

Save this as content_location_demo.py:

from http.server import BaseHTTPRequestHandler, HTTPServer

BODY = b"Example report in English.\n"


class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path not in ("/report", "/report.en"):
            self.send_error(404)
            return

        self.send_response(200)
        self.send_header("Content-Type", "text/plain; charset=utf-8")
        self.send_header("Content-Language", "en")
        if self.path == "/report":
            self.send_header("Content-Location", "/report.en")
        self.send_header("Content-Length", str(len(BODY)))
        self.end_headers()
        self.wfile.write(BODY)


if __name__ == "__main__":
    server = HTTPServer(("127.0.0.1", 8000), Handler)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
    finally:
        server.server_close()

Start the server in one terminal:

python3 content_location_demo.py

In another terminal, request each resource and compare the bodies:

curl --fail --silent --show-error \
  --dump-header report.headers --output report.body \
  http://127.0.0.1:8000/report

curl --fail --silent --show-error \
  --dump-header report-en.headers --output report-en.body \
  http://127.0.0.1:8000/report.en

cat report.headers
cat report-en.headers
cmp report.body report-en.body

The first headers file should contain Content-Location: /report.en; the second should not. Both responses should be 200, and cmp should find identical body bytes. The code is designed to produce that result, but the requests and comparison were not run here. Stop the server with Ctrl-C when finished.

This comparison demonstrates the server's claim for these two requests. In a real service, compare relevant metadata too, such as Content-Type, Content-Language, and content encoding. Matching bodies at one moment do not establish that the URLs will always be equivalent.

Advertisement

Caching and implementation caveats

A cache's handling of a response depends on HTTP caching rules, request method, status, cache directives, and relevant request headers. Do not assume that Content-Location alone changes the cache key or makes a response stored for one URL automatically reusable for another.

If a server selects a representation based on request headers, it must also consider the appropriate Vary response field so caches can distinguish selections. For example, a service that chooses a language using Accept-Language may need to vary on that field. The local example always serves English and therefore does not demonstrate negotiation.

A Content-Location URI can be relative or absolute. Resolve relative values correctly, and treat the result as untrusted input if your application fetches it. A server-side fetcher needs its own authorization, destination and redirect checks, network restrictions, and resource limits; parsing the header is not an SSRF defense.

Common Mistakes

  • Following the header as a redirect. Content-Location does not tell a client to navigate or repeat the request.
  • Equating it with the requested URL. A different value identifies an associated URI; it does not rewrite the request target.
  • Treating it as a canonical SEO directive. Representation identity and a preferred indexing URL answer different questions.
  • Assuming permanent byte equality. A later request can produce a different result, even if an earlier comparison matched.
  • Assuming automatic cache sharing. Check the actual caching and negotiation rules rather than inferring them from this field alone.

Best Practices

Document the request method, status, request target, resolved Content-Location, and relevant representation headers together. When investigating a discrepancy, fetch both URIs with comparable request headers and credentials, then compare status, metadata, and body. Avoid logging credentials or sensitive response bodies while doing so.

Conclusion

Content-Location helps explain which URI a server associates with a response representation. Use it as context for interpreting and comparing representations—not as a redirect, canonicalization guarantee, or substitute for cache and security controls.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.