Dev.to
7/20/2026

Fixing canonical tag mismatches with www redirects in Next.js for Google indexing
Original: I spent 2 days debugging why Google wouldn't index my new SaaS — the bug was in my own canonical tags
Short summary
A developer launched a new SaaS site and found Google Search Console showing indexing problems caused by canonical tags pointing to the non-www version while the server redirected to www. The fix involved pulling hardcoded domain references into a shared constant and ensuring canonical tags and JSON-LD URLs matched the redirect target. The author notes that TypeScript and test suites won't catch this—only a live view-source will.
- •Canonical tags pointed to non-www while server redirected to www, sending contradicting signals to Google
- •Fix: centralize domain references in a shared constant and align canonical/JSON-LD URLs with redirect target
- •tsc and test suites won't catch this; only a live view-source reveals the mismatch
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



