fix: rewrite redirect targets and preserve recursive crawling by JustinBeckwith · Pull Request #878 · JustinBeckwith/linkinator · GitHub
Skip to content

fix: rewrite redirect targets and preserve recursive crawling - #878

Merged
JustinBeckwith merged 2 commits into
mainfrom
codex/fix-redirect-rewrites-and-crawling
Aug 17, 2026
Merged

JustinBeckwith merged 2 commits into
mainfrom
codex/fix-redirect-rewrites-and-crawling

Conversation

@JustinBeckwith

@JustinBeckwith JustinBeckwith commented Aug 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • apply URL rewrite expressions to every HTTP redirect target before requesting or evaluating skip rules
  • support urlRewriteExpressions from JSON and JavaScript config files in the CLI
  • preserve the effective final URL when redirects are followed manually so recursive relative links are resolved and crawled from the destination page
  • isolate HTTP transport and redirect mechanics in a focused request module with one typed rewrite-and-skip policy
  • document redirect rewrite behavior and JSON pattern syntax

Root cause

URL rewrites were only applied when a URL first entered crawl(). Redirect targets were followed inside makeRequest() without passing through the rewrite pipeline, so rewritten destinations could still hit the original host.

Manual redirect handling also relied on the fetch response's URL metadata for the effective destination. Tracking the final URL explicitly makes recursive parsing deterministic and ensures relative links discovered on the redirect destination use the correct base URL.

User impact

Redirected URLs now behave consistently with directly discovered URLs: rewrites run at every hop, skip rules see the rewritten destination, sensitive headers remain protected across origin changes, and destination documents continue to contribute recursively discovered links.

The maintainability review also reduced src/index.ts by 187 lines relative to main and kept redirect rewrite coverage out of the existing redirect test file, which would otherwise have crossed 1,000 lines.

Fixes #877.
Fixes #875.

Validation

  • npm run build
  • npm test -- --run — 259 tests passed
  • npm run coverage — 94.03% statements, 89.06% branches, 98% functions
  • npm run lint
  • npm run docs-test — 17 links passed
  • npm pack --dry-run --json
  • npm run build-binaries
  • Node CLI and macOS standalone binary --version smoke tests

Comment thread src/cli.ts Fixed
@JustinBeckwith
JustinBeckwith marked this pull request as ready for review August 17, 2026 04:35
@JustinBeckwith
JustinBeckwith force-pushed the codex/fix-redirect-rewrites-and-crawling branch from 143b944 to c2278e8 Compare August 17, 2026 04:41
Comment thread src/cli.ts Dismissed
@JustinBeckwith
JustinBeckwith force-pushed the codex/fix-redirect-rewrites-and-crawling branch from 0291161 to 472cdac Compare August 17, 2026 04:46
@JustinBeckwith
JustinBeckwith merged commit 7d99a3b into main Aug 17, 2026
8 checks passed
@JustinBeckwith
JustinBeckwith deleted the codex/fix-redirect-rewrites-and-crawling branch August 17, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redirects May Not Follow urlRewriteExpressions Redirect targets are no longer checked for new URLs after #846

2 participants