How to Redirect www to non-www (or vice versa) in .htaccess: Canonical SEO Guide

Advertisement

Google AdSense In-Article Display Placement

Publisher ID: ca-pub-XXXXXXXXXXXXXXXX (Configured in config.php)

Search engines treat "www.gardenwargame.online" and "gardenwargame.online" as two distinct websites unless unified. Learn how to configure a 301 redirect to enforce a single canonical domain version.

✔ Rapid Direct Solution

To enforce non-www: add RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] -> RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L] inside your .htaccess file. This strips "www" seamlessly while maintaining full URL paths and query parameters.

1. Problem Diagnosis & Symptoms

Split domain traffic dilutes inbound backlinks across two different hostname variants.

2. Primary Root Causes

  • Cause: Missing hostname unification directives.

3. Step-by-Step Diagnostic Fixes

1

Add non-www Rewrite Rule

Edit .htaccess:

APACHECONF
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>

4. How to Verify the Resolution

  • ✔ Open https://www.gardenwargame.online and confirm it redirects to https://gardenwargame.online.

5. Diagnostic Troubleshooting Matrix

Symptom Observed Root Cause Recommended Action
SSL certificate error on www subdomain SSL certificate issued only for root domain without www SAN Re-issue SSL certificate covering both @ and www

6. Critical Mistakes to Avoid

  • ❌ Leaving both versions accessible without canonical 301 redirection.

7. Frequently Asked Questions

❓ Is non-www better for SEO than www?

Google treats both equally; consistency is what matters for link consolidation.

Official Technical References

Advertisement

Google AdSense In-Article Matched Content Unit