The Referer HTTP header records the origin of a request, allowing web applications to track navigation flows, enforce access rules, or adapt responses based on where traffic appears to come from. Controlling this header helps reproduce browser-like behavior in automated tests and scripts that rely on cURL.

During an HTTP request, cURL constructs headers and metadata before sending them over HTTP or HTTPS, and the --referer option injects a dedicated Referer header into that set. Using verbose mode exposes the raw request so the exact header and its value can be inspected without relying solely on application logs.

Altering or forging the Referer header can affect analytics, reputation filters, or access control that assumes a trustworthy origin, and some protections treat missing or blank referrers differently. Any change to this header should be tested against non‑production endpoints first, with awareness that referer checks do not provide strong security guarantees on their own.

Steps to set a custom referrer in cURL:

  1. Open a terminal where cURL is available in the current environment.

    cURL behaves consistently across most Unix-like systems, containers, and shells when using the same command-line options.

  2. Send a request that includes a specific Referer header using --referer.
    $ curl --referer "https://example-referrer.test/page" "https://example.com/resource"
    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
    ##### snipped #####

    The --referer option adds an HTTP Referer header with the given URL so the target server sees the request as coming from that origin.

  3. Enable verbose mode to confirm the header is present in the outgoing request.
    $ curl --referer "https://example-referrer.test/page" --verbose "https://example.com/resource"
    ##### snipped #####
    > GET /resource HTTP/1.1
    > Host: example.com
    > User-Agent: curl/7.81.0
    > Accept: */*
    > Referer: https://example-referrer.test/page
    ##### snipped #####

    Success signal: verbose output shows a line beginning with > Referer: followed by the configured URL.

  4. Simulate a direct visit with no meaningful origin by sending an empty Referer value.
    $ curl --referer "" "https://example.com/resource"
    ##### snipped #####

    Some applications block or alter responses for missing or blank Referer headers, which can cause automation to fail even when manual browser access works.

  5. Verify how the header is received by calling an echo endpoint that returns request headers.
    $ curl --referer "https://example-referrer.test/page" "https://httpbin.org/headers"
    {
      "headers": {
        "Accept": "*/*",
        "Host": "httpbin.org",
        "Referer": "https://example-referrer.test/page",
    ##### snipped #####
      }
    }

    Success signal: the echoed JSON shows a Referer key with the expected URL when set, and omits or empties the value when an empty referer is used.

  6. Apply automatic referer behavior on redirects when mimicking browser navigation.
    $ curl --referer ";auto" --location "https://example.com/start"
    ##### snipped #####

    The special value ";auto" instructs cURL to populate subsequent Referer headers on redirects, matching typical browser behavior more closely.

Discuss the article:

Comment anonymously. Login not required.