www vs non-www redirects correct
Issue No: 10
Category: Crawl Behaviour
Issue type: Issue
Priority: CRITICAL
Description
Verifies that both hostname variants (www and non-www) resolve to a single canonical host through consistent redirects. This prevents duplicate crawl paths and index fragmentation caused by host-level URL duplication.
How do we capture it
- Build two test URLs for the same root host and scheme scope:
- Variant A:
https://example.com/ - Variant B:
https://www.example.com/Use the audited domain as the base and preserve HTTPS as the primary protocol for checks.
- Variant A:
- Send independent HTTP
GETrequests for both variants with redirects disabled on first request (maxRedirects = 0) to capture raw status andLocationheader. - If either response is a redirect (
3xx), follow redirects manually hop-by-hop up to a fixed limit (for example, 10 hops), recording each intermediate URL, status code, andLocationvalue. - Normalize each observed URL in the chain for comparison:
- Lowercase scheme and host.
- Remove default ports (
:80,:443). - Preserve path, query, and fragment as received.
- Normalize trailing slash only for root-path canonical comparison.
- Determine final landing URL for each variant after redirect following completes or stops on non-redirect response.
- Evaluate canonical host consistency:
- Pass condition requires both variant requests to end on the same final canonical host and equivalent canonical URL target.
- Redirect loops, missing
Locationon3xx, timeout, DNS failure, TLS failure, or hop-limit overflow are capture failures.
- Record chain diagnostics for each variant, including total hops and terminal status.
- Constraint: crawler logic is based only on HTTP responses/headers and final resolved URLs from requests. No browser rendering or JavaScript execution is involved.
What to store
| Field | Type | Comment |
|---|---|---|
| host_redirect_check_target TEXT | TEXT | Base audited host used to generate www/non-www variant requests. |
| non_www_test_url TEXT | TEXT | Full non-www variant URL requested by the crawler. |
| www_test_url TEXT | TEXT | Full www variant URL requested by the crawler. |
| non_www_initial_status_code INTEGER | INTEGER | First HTTP status code returned for non-www variant before manual redirect follow. |
| www_initial_status_code INTEGER | INTEGER | First HTTP status code returned for www variant before manual redirect follow. |
| non_www_redirect_chain JSONB | JSONB | Ordered hop records for non-www request with URL, status, and location per hop. |
| www_redirect_chain JSONB | JSONB | Ordered hop records for www request with URL, status, and location per hop. |
| non_www_final_url TEXT | TEXT | Final resolved URL for non-www variant after redirect traversal. |
| www_final_url TEXT | TEXT | Final resolved URL for www variant after redirect traversal. |
| non_www_final_host TEXT | TEXT | Final resolved hostname for non-www variant. |
| www_final_host TEXT | TEXT | Final resolved hostname for www variant. |
| non_www_hop_count INTEGER | INTEGER | Number of redirect hops followed for non-www variant. |
| www_hop_count INTEGER | INTEGER | Number of redirect hops followed for www variant. |
| non_www_fetch_error TEXT | TEXT | Network/protocol error text for non-www request when fetch or chain resolution fails. |
| www_fetch_error TEXT | TEXT | Network/protocol error text for www request when fetch or chain resolution fails. |
| is_www_non_www_redirect_consistent BOOLEAN | BOOLEAN | True when both variants converge to the same canonical destination host/URL. |
| canonical_redirect_target_host TEXT | TEXT | Canonical host selected by redirect behavior when consistency check passes. |
| checked_at TIMESTAMPTZ | TIMESTAMPTZ | Timestamp when redirect consistency audit was executed. |
Condition for trigger
The crawler should raise this issue when host canonicalization between www and non-www is missing, inconsistent, or technically broken.
-
Trigger Rule 1: Variants Do Not Converge
- Target Field:
is_www_non_www_redirect_consistent - Evaluation Logic:
is_www_non_www_redirect_consistent = FALSE - Severity: CRITICAL
- Diagnostic Message: "www and non-www versions do not resolve to one canonical destination, causing duplicate URL hosts."
- Target Field:
-
Trigger Rule 2: Non-www Variant Fetch Failed
- Target Field:
non_www_fetch_error - Evaluation Logic:
non_www_fetch_error IS NOT NULL AND non_www_fetch_error <> '' - Severity: CRITICAL
- Diagnostic Message: "The non-www variant could not be reliably resolved due to a network or protocol failure."
- Target Field:
-
Trigger Rule 3: www Variant Fetch Failed
- Target Field:
www_fetch_error - Evaluation Logic:
www_fetch_error IS NOT NULL AND www_fetch_error <> '' - Severity: CRITICAL
- Diagnostic Message: "The www variant could not be reliably resolved due to a network or protocol failure."
- Target Field:
Sources
- Google Search Central: https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
- RFC 9110 (HTTP Semantics): https://www.rfc-editor.org/rfc/rfc9110
- RFC 3986 (URI Generic Syntax): https://www.rfc-editor.org/rfc/rfc3986
- MDN Web Docs, HTTP Redirections: https://developer.mozilla.org/docs/Web/HTTP/Redirections
Long description
Search engines treat hostnames as distinct URL spaces unless explicit canonicalization is enforced. If www and non-www versions are both reachable without deterministic consolidation, crawlers can discover duplicate pages under separate hosts, splitting crawl budget and link equity.
A robust host canonicalization check requires network-level validation of both variants because redirect intent must be proven through actual response status codes and Location headers, not assumptions. The crawler should inspect redirect chains end-to-end and confirm both entry points terminate at one canonical destination.
Common failure scenarios checked by the crawler:
- One variant returns
200 OKwhile the other redirects, leaving both hosts indexable. - Both variants redirect, but to different final hosts or different canonical URL paths.
- Redirect loops occur between hosts or within chain hops.
- Redirect responses are malformed (for example,
3xxwithout validLocation). - Fetch failures prevent reliable determination of canonical host behavior.
How to Fix
Choose one canonical host strategy (www or non-www) and enforce it consistently at the edge/web server layer for all URLs. Ensure every request to the non-canonical host returns a deterministic redirect to the equivalent canonical URL, with no loops and no split destinations. Validate behavior for both root and deep URLs, confirm consistent protocol handling, and re-test until both variants always converge to one canonical endpoint.