<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: site check tools</title>
    <description>The latest articles on DEV Community by site check tools (@sitechecktools99).</description>
    <link>https://dev.to/sitechecktools99</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4182441%2F6c216d4c-4223-485d-bc82-afda82dff344.png</url>
      <title>DEV Community: site check tools</title>
      <link>https://dev.to/sitechecktools99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sitechecktools99"/>
    <language>en</language>
    <item>
      <title>Finding the 302 Hiding in Your Redirect Chain, With curl</title>
      <dc:creator>site check tools</dc:creator>
      <pubDate>Tue, 13 Oct 2026 15:17:42 +0000</pubDate>
      <link>https://dev.to/sitechecktools99/finding-the-302-hiding-in-your-redirect-chain-with-curl-3660</link>
      <guid>https://dev.to/sitechecktools99/finding-the-302-hiding-in-your-redirect-chain-with-curl-3660</guid>
      <description>&lt;p&gt;A redirect chain is a redirect that points at another redirect. Browsers follow the whole sequence without showing it, so a chain can sit on a site for years. Here is how to see one with curl, what to look for, and how to collapse it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a chain looks like
&lt;/h2&gt;

&lt;p&gt;Take a site that has three sensible rules: force HTTPS, force &lt;code&gt;www&lt;/code&gt;, and send an old path to a new one. Each rule is correct. Together they turn one request into three hops (the hostnames below are placeholders):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://example.com/old-page
  -&amp;gt; https://example.com/old-page        301
  -&amp;gt; https://www.example.com/old-page    301
  -&amp;gt; https://www.example.com/new-page    302
  -&amp;gt; 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Trace it by hand
&lt;/h2&gt;

&lt;p&gt;Ask curl for headers only, and tell it to follow redirects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sIL&lt;/span&gt; http://example.com/old-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-I&lt;/code&gt; sends a HEAD request, &lt;code&gt;-L&lt;/code&gt; follows each &lt;code&gt;Location&lt;/code&gt; header, and &lt;code&gt;-s&lt;/code&gt; hides the progress bar. The output is one block of headers per hop. Two lines in each block matter: the status line and &lt;code&gt;Location&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To cut it down to those lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sIL&lt;/span&gt; http://example.com/old-page | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-iE&lt;/span&gt; &lt;span class="s1"&gt;'^(HTTP|location)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a one-line summary, use curl's write-out variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sIL&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /dev/null &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="s1"&gt;'%{num_redirects} hops, ends at %{url_effective}\n'&lt;/span&gt; http://example.com/old-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some servers answer HEAD differently from GET. If the result looks wrong, swap &lt;code&gt;-I&lt;/code&gt; for &lt;code&gt;-o /dev/null -D -&lt;/code&gt; so curl sends a GET and prints the headers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each hop costs
&lt;/h2&gt;

&lt;p&gt;Every hop is a full round trip before the browser can ask for the page it actually wants. When a hop changes the protocol or the hostname, the browser also needs a new connection, which means another DNS lookup and another TLS handshake. On a slow mobile connection that is time the visitor spends looking at nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 302 is the real problem
&lt;/h2&gt;

&lt;p&gt;Look at the status codes, not only the count. A 301 says the move is permanent. A 302 says it is temporary. One 302 in a chain of 301s makes the whole sequence ambiguous: a crawler cannot be sure the final URL is the permanent home of the content. In the example above, the last hop is the one to fix.&lt;/p&gt;

&lt;p&gt;In the curl output it is easy to miss, because it is one status line among several. The &lt;code&gt;grep&lt;/code&gt; above puts every status code in a column so the odd one stands out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where chains come from
&lt;/h2&gt;

&lt;p&gt;Usually from rules living in more than one place: the CDN, the web server, the application, and a CMS plugin. Each rule was written by someone who could not see the others. Nobody wrote a chain on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Point every rule at the final URL so any request arrives in one hop. In Nginx, that means the plain-HTTP server block and the bare-domain block both redirect straight to the canonical origin, and the path redirect names the full final URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Before: each block hands off to the next one&lt;/span&gt;
&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;example.com&lt;/span&gt; &lt;span class="s"&gt;www.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;301&lt;/span&gt; &lt;span class="s"&gt;https://&lt;/span&gt;&lt;span class="nv"&gt;$host$request_uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# After: every variant goes straight to the canonical origin&lt;/span&gt;
&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;example.com&lt;/span&gt; &lt;span class="s"&gt;www.example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;301&lt;/span&gt; &lt;span class="s"&gt;https://www.example.com&lt;/span&gt;&lt;span class="nv"&gt;$request_uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;location&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;/old-page&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;301&lt;/span&gt; &lt;span class="s"&gt;https://www.example.com/new-page&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the curl command again against every variant of the URL: &lt;code&gt;http&lt;/code&gt;, &lt;code&gt;https&lt;/code&gt;, with and without &lt;code&gt;www&lt;/code&gt;. Each should report one hop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits of this method
&lt;/h2&gt;

&lt;p&gt;curl follows HTTP redirects only. It will not see a &lt;code&gt;&amp;lt;meta http-equiv="refresh"&amp;gt;&lt;/code&gt; tag or a redirect done in JavaScript. A server can also answer curl differently from a browser, based on the user agent or cookies. If the browser ends up somewhere curl does not, that is the reason.&lt;/p&gt;

&lt;p&gt;If you would rather not read headers by eye, a &lt;a href="https://sitechecktools.com/redirect-checker/" rel="noopener noreferrer"&gt;redirect checker&lt;/a&gt; prints the same hops with their status codes and flags loops. Disclosure: I build that one.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>http</category>
      <category>seo</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
