Link Rules

Link Rules

Rules for validating links and link structure.

broken-links

Checks all links for broken/invalid status codes.

Checks

  • Internal links return 200
  • External links are reachable
  • No 404, 500, or other error codes
  • Handles redirects (up to 10 hops)

Requires

Live checks enabled (default). Disable with --no-live.

Examples

Fail:

<a href="/old-page">Link</a> <!-- Error: Broken link: /old-page (404) --> <a href="https://example.com/missing">External</a> <!-- Error: Broken link: https://example.com/missing (404) -->

Pass:

<a href="/about">About Us</a> <!-- Returns 200 OK -->

Configuration

rules: { 'broken-links': { severity: 'error', enabled: true, // or false to disable }, }

Disable for Static Analysis

capyseo analyze ./dist --no-live

redirect-chains

Detects chains of 2+ redirects.

Checks

  • Links that redirect multiple times
  • Recommends direct linking

Examples

Warning:

<a href="/old">Link</a> <!-- /old → /old2 → /new (2 redirects) --> <!-- Warning: Redirect chain detected (2 hops) -->

Better:

<a href="/new">Link</a> <!-- Direct link, no redirects -->

Why It Matters

  • Slower page loads
  • Lost link equity
  • Poor user experience

Configuration

rules: { 'redirect-chains': { severity: 'warning', }, }

external-links

Validates external links with target="_blank" have rel="noopener".

Checks

  • target="_blank" links have rel="noopener"
  • Prevents security vulnerabilities

Examples

Fail:

<a href="https://external.com" target="_blank">External</a> <!-- Warning: External link missing rel="noopener" -->

Pass:

<a href="https://external.com" target="_blank" rel="noopener">External</a> <a href="https://external.com" target="_blank" rel="noopener noreferrer">External</a>

Why It Matters

Without rel="noopener", the opened page can access window.opener and potentially redirect your page.

Configuration

rules: { 'external-links': { severity: 'warning', }, }

internal-links

Analyzes internal linking structure.

Checks

  • Page has at least 3 internal links
  • Warns if too few internal links

Examples

Warning:

<body> <a href="/">Home</a> <!-- Only 1 internal link --> <!-- Info: Low internal link count (1). Consider adding more. --> </body>

Pass:

<nav> <a href="/">Home</a> <a href="/about">About</a> <a href="/blog">Blog</a> <a href="/contact">Contact</a> </nav>

Why It Matters

Internal links help:

  • Search engines discover pages
  • Distribute page authority
  • Improve user navigation

Configuration

rules: { 'internal-links': { severity: 'info', }, }

Best Practices

Link Text Guidelines

Good Bad
"View our pricing plans" "Click here"
"Read the full article" "More"
"Download the PDF guide" "Link"

Security Checklist

  • All target="_blank" have rel="noopener"
  • No links to compromised domains
  • HTTPS links where possible

Internal Linking

  • Link to related content
  • Use descriptive anchor text
  • Include navigation links
  • Add contextual links in content

Example Good Linking

<article> <h1>React Hooks Guide</h1> <p> Before learning hooks, make sure you understand <a href="/guides/react-basics">React fundamentals</a>. </p> <p> For more advanced patterns, see our <a href="/guides/advanced-hooks">advanced hooks guide</a>. </p> </article> <nav> <a href="/" rel="home">Home</a> <a href="/guides">Guides</a> <a href="https://github.com/example" target="_blank" rel="noopener">GitHub</a> </nav>