← Mac Change Notes

Why curl Shows 301 Instead of the Page

Use curl -L to follow an HTTP redirect. By default, curl can stop at a 301 Moved Permanently response while a browser follows its Location header. Check the final URL and status: following a redirect does not guarantee a successful page.

In this article

A redirect is a server response, not necessarily a failed connection. The useful distinction is between receiving that response, following its instruction, and getting the content you actually wanted. Each is a separate observation.

Start with the built-in command

In Terminal, use /usr/bin/curl -q -L "https://example.com/", replacing the example address with the public URL you intend to check. -L is short for --location. The first-position -q skips curl’s default configuration file, making this diagnostic less dependent on local settings.

You do not need another networking app just to follow a normal HTTP redirect. The curl project’s redirect guide explains the default behavior and the extra request made when redirect following is enabled.

ObservationWhat it establishesWhat to check next
HTTP 301 with a Location headerThe server points to another addressFollow the intended destination
A final HTTP 200 after -LThe last server response was successfulConfirm it is the expected content
A final HTTP 404 after -LThe redirect target was not foundReview the final address
curl exit code 0The transfer met curl’s current error rulesRead the HTTP status too
curl error 47The configured redirect limit was exceededInspect the redirect chain

These examples concern ordinary GET requests. Do not apply a GET troubleshooting recipe unchanged to a form submission or an authenticated API request.

Read where the redirect actually leads

For a compact diagnostic, discard the response body and print three separate results:

/usr/bin/curl -q -sS -L --max-redirs 5 --max-time 20 \
  -o /dev/null \
  -w 'status=%{http_code} redirects=%{num_redirects} final=%{url_effective}\n' \
  'https://example.com/'

Replace the example URL. -sS suppresses the progress meter while retaining error messages. --max-redirs 5 bounds redirect following, and --max-time 20 bounds the transfer time in seconds. The printed status is the last HTTP response, the count is the number of redirects followed, and the effective URL is where curl ended.

To see the response headers as well, add -D - to that command. Keep -o /dev/null when you want the headers without a potentially long body. This still makes a GET request.

Using -I instead asks for HEAD. Some servers handle HEAD differently, so a HEAD result is not always a substitute for the GET you are investigating. See why curl -I can return 405 if that is the mismatch you actually have.

The curl project’s guide shows the option for following redirects

Screenshot: everything curl, captured November 28, 2026. Redirect following is an explicit curl option.

Our test: the same redirect, different commands

On November 28, 2026, we ran Apple’s /usr/bin/curl 8.7.1 on macOS 15.7.5, build 24G624 against a disposable HTTP server bound only to 127.0.0.1. The server recorded the actual request paths. No external website or account was involved.

One endpoint returned a 301 pointing to a second endpoint that returned 200. Another redirected to a missing page, and a third redirected back to itself. We kept proxy settings and local curl configuration out of this controlled loopback test.

TestRequests observedFinal HTTP statuscurl exit code
Plain request to the 301 endpointOriginal path only3010
Same request with -LOriginal and target paths2000
Redirect to a missing page with -LOriginal and missing paths4040
Same missing-page case with -L --failOriginal and missing paths40422
Self-redirect with -L --max-redirs 3Four requests to the loop path30247

The first two rows isolate the effect of -L: the server saw an additional request only when curl was instructed to follow. The next two show why an exit status by itself can mislead a script. The loop row shows that a limit of three followed redirects still allows the initial request plus those three follow-up requests.

This experiment verifies these HTTP behaviors in the stated environment. It does not test TLS certificates, browser cookies, authentication, or the behavior of every installed curl version.

A successful transfer can still end at an error page

Curl normally distinguishes a transfer failure from an HTTP response that happens to be an error. Receiving a complete 404 response can therefore produce exit code 0, as our test demonstrated.

For a check that should fail on HTTP error responses, the documented --fail option changes that behavior. It does not make 301 itself an error, and it does not establish that a 200 response contains the right page. A login page or a generic application screen can still be a successful HTTP response.

Check the final URL, HTTP status and expected content together. The curl manual documents --location, --fail, the redirect limit and the output variables used here; local man curl describes the version installed on your Mac.

Know where browser comparisons stop

A browser may have cookies, cached redirects, JavaScript and an authenticated session that this curl command does not have. Curl’s redirect option follows HTTP redirects; it does not turn curl into a browser that executes a page’s JavaScript navigation.

The HTTP semantics standard distinguishes redirect status codes and their method rules. In particular, POST handling can change across redirects. Avoid adding arbitrary -X method overrides just to make a result resemble a browser trace.

A redirect can also change hosts. Do not solve an ordinary 301 by adding --location-trusted, which changes credential forwarding, or by disabling certificate checks. If the remaining problem is a proxy difference, investigate curl and macOS system proxy settings separately.

For a practical result, preserve the original URL, final URL, HTTP status, redirect count and curl version. That record tells you whether you followed the move and what answered at the other end, instead of treating the first 301 or a lone zero exit code as the whole diagnosis.