Skip to Content

www and non-www versions not resolved to one

What Is This Issue

Websites can typically be accessed with or without the www prefix (e.g., both https://example.com and https://www.example.com). This issue checks whether both hostname variants resolve to a single canonical host through consistent redirects, preventing duplicate content and URL fragmentation.

A passing implementation requires:

  • Both www and non-www versions redirect to the same canonical hostname
  • Consistent redirects for all URLs (not just the homepage)
  • No redirect loops between www and non-www variants
  • Proper HTTP to HTTPS redirects in addition to www canonicalization

Example: When a user visits https://www.example.com, they are automatically redirected to https://example.com (or vice versa), and this redirect is consistent across all pages.

Why Is This Important

Proper www vs non-www canonicalization is important for SEO because it:

  • Prevents Duplicate Content: Search engines might index both versions separately, splitting ranking signals
  • Consolidates Link Equity: Inbound links to both versions get consolidated to a single canonical URL
  • Improves Crawl Efficiency: Search engines don’t waste crawl budget on duplicate hosts
  • Strengthens Rankings: Consolidated signals help improve search rankings for the canonical URL

Without proper canonicalization, search engines may treat www and non-www versions as separate websites, diluting your SEO efforts and potentially causing duplicate content issues.

How XeoPix Detects This

XeoPix performs www vs non-www canonicalization checks through the following logical steps:

  1. Hostname Discovery: XeoPix crawls URLs from both the www and non-www versions of your domain to see how they respond.

  2. Redirect Tracking: For each URL variant, XeoPix follows redirects and records the final destination hostname.

  3. Consistency Check: XeoPix verifies that:

    • All www URLs redirect to the same canonical hostname
    • All non-www URLs redirect to the same canonical hostname
    • The canonical hostname is consistent across all pages (not just the homepage)
  4. Loop Detection: XeoPix checks for redirect loops between www and non-www variants.

  5. HTTPS Verification: XeoPix ensures that HTTP versions also redirect to HTTPS.

  6. Issue Identification: XeoPix raises issues when:

    • Both www and non-www versions are accessible without redirecting (CRITICAL)
    • Redirects are inconsistent across different pages (WARNING)
    • Redirect loops are detected (CRITICAL)
    • HTTP doesn’t redirect to HTTPS (WARNING)
    • The canonical hostname changes between pages (CRITICAL)

How To Fix

  1. Choose your canonical hostname: Decide whether you want your canonical URL to include www or not (e.g., https://example.com vs https://www.example.com).

  2. Configure server-side redirects: Set up 301 redirects at your web server or CDN level to redirect the non-canonical version to the canonical version.

  3. Redirect all URLs: Ensure the redirect applies to all pages, not just the homepage (e.g., https://www.example.com/products should redirect to https://example.com/products).

  4. Handle HTTP to HTTPS: Ensure HTTP versions also redirect to the HTTPS canonical version.

  5. Update internal links: Use the canonical hostname consistently in all internal links.

  6. Verify with external tools: Use online redirect checkers to confirm the redirects work correctly for various URL paths.

  7. Monitor regularly: Periodically check that the canonicalization remains consistent and hasn’t been accidentally broken by server configuration changes.

What We Store

Storage Level

Page Level — This issue is evaluated for each individual URL that returns a redirect.


Database Table / Prisma Model

RedirectChain


Stored Fields

FieldTypeDescription
originalUrlStringThe original URL that was requested
finalUrlStringThe final URL after all redirects
chainJsonArray of all redirect hops (URLs and status codes)
chainLengthIntNumber of redirects in the chain
hasLoopBooleanWhether the redirect chain contains a loop

Detection Dependencies

  • The following data sources are required to evaluate this issue:
  • HTTP Response — The crawler follows redirect responses (301, 302, 303, 307, 308)
  • Redirect Chain — All intermediate URLs and status codes are captured
  • Final URL — The destination URL after all redirects are followed

Examples

Example 1: Inconsistent WWW vs Non-WWW

Problematic State (Fails): Both versions are accessible without redirecting:

  • https://example.com returns 200 OK
  • https://www.example.com returns 200 OK

Search engines may index both as separate pages.

Corrected State (Passes): Choose one canonical version and redirect the other:

  • https://www.example.com → 301 redirect → https://example.com
  • https://example.com returns 200 OK (canonical)

Example 2: Partial Redirects

Problematic State (Fails): Only the homepage redirects, but inner pages don’t:

  • https://www.example.comhttps://example.com (redirects)
  • https://www.example.com/products returns 200 OK (no redirect)

Corrected State (Passes): Ensure all pages redirect consistently:

  • https://www.example.comhttps://example.com
  • https://www.example.com/productshttps://example.com/products
  • https://www.example.com/abouthttps://example.com/about

Example 3: Redirect Loop

Problematic State (Fails): Circular redirects between www and non-www:

  • https://example.comhttps://www.example.com
  • https://www.example.comhttps://example.com

Corrected State (Passes): Break the loop by redirecting consistently to one canonical version:

  • https://example.com returns 200 OK (canonical)
  • https://www.example.com → 301 redirect → https://example.com

Unit Test

Test File

xeopix-crawling-v2/__tests__/seo-audit-checks/crawlBehaviour/issue-10-www-vs-non.test.js

Purpose

This unit test validates that the checkWwwVsNonRedirect() function correctly determines whether a website properly redirects between www and non-www versions of the domain, ensuring only one canonical version is accessible.

Tested Function

checkWwwVsNonRedirect() from seo-audit-checks.js

Issue Information

  • Issue Number: 10
  • Issue Code: WWW_VS_NON
  • Toggle Group: crawlBehaviour

Test Scenarios

Positive Test Cases

  • The preferred version returns HTTP 200 and the other version redirects with HTTP 301 to the preferred version → no issue, hasRedirect is true, preferredVersion is set

Negative Test Cases

  • Both www and non-www versions resolve without a proper 301 redirect → WWW_VS_NON issue created with status missing-redirect and message containing 'both serve content'

Boundary Cases

None

Edge Cases

  • Empty input string → no issues created, preferredVersion is null, hasRedirect is false

Expected Outcome

Pass

A WWW_VS_NON issue is not reported when one version returns 200 and the other version returns 301 redirecting to it.

Fail

A WWW_VS_NON issue is reported with status missing-redirect when both versions return HTTP 200 without redirecting to a canonical hostname.

Validation

  • Verifies correct detection of proper www/non-www redirect setup
  • Validates issue creation when both versions serve content independently
  • Checks return structure (detectedIssues, hasRedirect, preferredVersion)
  • Ensures empty input is handled safely without creating false issues
  • xeopix-crawling-v2/seo-audit-checks.js
  • xeopix-crawling-v2/issueCodes.js

Coverage Summary

  • 3 test cases (positive, negative, and edge case)
  • Covers the primary redirect detection logic
  • Validates payload structure and status codes
  • Includes empty input safety handling

References

Last updated on