Back to cheatsheets
Web Security
Redirect Chain Tracing
Trace HTTP redirect hops, detect loops, and identify the final destination URL.
What you'll learn
- Trace redirects with curl
- JavaScript redirect tracer
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for redirect chain tracing. Click copy and paste into your project.
Trace redirects with curl
# Follow redirects and show each hop
curl -L -o /dev/null -w \
'%{url_effective} → %{http_code}\n' \
https://example.com
# Verbose redirect trace
curl -vIL https://short.url/abc123 2>&1 | \
grep -i 'location:\|HTTP/'
# Detect redirect loops
curl -L --max-redirs 10 https://example.com
# If max-redirs is hit, you have a loop
JavaScript redirect tracer
async function traceRedirects(url) {
const hops = [];
let current = url;
const visited = new Set();
for (let i = 0; i < 20; i++) {
if (visited.has(current))
return { hops, loop: true };
visited.add(current);
const res = await fetch(current, {
redirect: 'manual',
method: 'HEAD'
});
hops.push({ url: current, status: res.status });
const location = res.headers.get('location');
if (!location || ![301,302,303,307,308]
.includes(res.status)) break;
current = new URL(location, current).href;
}
return { hops, loop: false };
}
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site