X
X
X
X

Knowledge Base

HomepageKnowledge BaseGeneralHow to Check HTTP Headers with curl...

How to Check HTTP Headers with curl: Redirects, Cache and Status Codes

In short: To check HTTP headers with curl, type curl -I https://yourdomain.com in a terminal. The command sends the server a HEAD request that asks only for the headers; the first line of the output shows the status code and the following lines show redirect, cache and security headers. Because the browser cache is not involved, it gives a quick, neutral answer to "why can't I see my change?".

Check HTTP headers with curl: curl -I and http_code commands in a terminal, a HEAD request to the server, HTTP/2 200, cache-control and location headers

What is curl and is it on your computer?

curl is a free command-line tool that sends a request to an address and shows the server's answer. Windows 10 version 17063 and later include curl, and it runs directly from Command Prompt. In Windows PowerShell, typing curl may run a different command, so type curl.exe there. On macOS use the Terminal app, on Linux any terminal; if it is missing, add it with your distribution's package manager.

How do you check HTTP headers with curl?

  1. Open a terminal: Command Prompt or PowerShell on Windows, Terminal on macOS, any terminal on Linux.
  2. Request the headers: this command fetches the headers only:
    curl -I https://yourdomain.com
    The first line of the output is the protocol and status code, such as HTTP/2 200; each line below holds one header and its value.
  3. Follow the redirect chain: with -L, curl follows the Location header of a 3xx answer, repeats the request and shows the headers of every step:
    curl -IL http://yourdomain.com
    This shows how many steps it takes to get from http to https or from the bare domain to www.
  4. Get only the status code: on Linux and macOS this command prints just the number, which is handy in monitoring scripts:
    curl -s -o /dev/null -w "%{http_code}" https://yourdomain.com
  5. Check with a normal request instead of HEAD: some applications answer HEAD differently from GET. On Linux and macOS, to discard the page body and show only the headers:
    curl -s -D - -o /dev/null https://yourdomain.com

Which headers should you look at?

HeaderWhat it tells youWhat to check
Status line (HTTP/2 200)The result of the request200 means fine, 301/302 a redirect, 404 not found, 5xx a server error; see our HTTP status codes guide for details.
locationWhere a redirect pointsCheck that the target is the right domain and uses https; for setting up permanent redirects see our 301 redirect article.
cache-controlCaching instructions for browsers and intermediariesIf a change does not show, this tells you how long the page is kept in cache.
content-typeType and character set of the contentCheck the charset value when special characters look broken.
strict-transport-security, x-content-type-options, x-frame-optionsSecurity headersConfirms which ones are actually sent; see our HTTP security headers article for what they mean.
server, cf-cache-statusThe server or intermediary that answeredOn sites behind Cloudflare, cf-cache-status shows whether the page came from Cloudflare's cache.

Common situations

  • Testing a new server before changing DNS: curl's --resolve option points the domain at an IP address you choose and works like a one-command hosts file:
    curl -I --resolve yourdomain.com:443:NEW_SERVER_IP https://yourdomain.com
    To run the same test in a browser, use our guide on the hosts file for testing a new server.
  • Certificate errors: curl verifies the SSL certificate by default and fails on an invalid one. -k skips this check; use it only for deliberate tests. To check when a certificate expires, see checking SSL certificate expiry.
  • A change does not show in the browser: if the status code and location value in the curl output are what you expect, the server is answering correctly and the old view most likely comes from your browser cache. In that case, clear your browser cache. The cache-control and cf-cache-status values also hint at which layer is keeping the old copy.
  • More detail: the -v option shows the whole exchange, marking headers sent with > and headers received with <.

The official description of every option is in the curl manual.

Frequently Asked Questions

Why can curl -I show something different from the browser?

The browser may show the page from its own cache and sends cookies, while curl makes a fresh request every time. curl -I is also a HEAD request, and some applications answer it differently. To be sure, also check with a normal request using curl -s -D - -o /dev/null.

What if the curl command does not work on Windows?

Windows 10 version 17063 and later include curl. In PowerShell, type curl.exe instead of curl. On an older Windows version you need to download curl from its official website.

Can curl show which server answered for my site?

Partly. The server header can show the software or intermediary; sites behind Cloudflare show server: cloudflare. The -v option also prints the IP address curl connected to.

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(6 times viewed / 0 people found it helpful)

Powered by WISECP
Top