WWW vs Non-WWW Configuration
Choosing and Configuring Your Canonical Domain
Every site should have a single canonical URL — either www.example.com or example.com (without www). Using both without a redirect causes duplicate content issues for SEO and can trigger redirect loops.
Choosing Your Canonical URL
- Non-WWW (
example.com) — shorter, modern, preferred by most new sites - WWW (
www.example.com) — allows CNAME at root (useful for CDNs), easier cookie scoping
Neither is technically better. Pick one and be consistent.
Step 1: Set WordPress URLs
sudo wp option update siteurl "https://example.com" --path=/home/DOMAIN/public_html --allow-root
sudo wp option update home "https://example.com" --path=/home/DOMAIN/public_html --allow-root
Step 2: OLS Redirect Rule
Add a redirect in your OLS vhost configuration to redirect the non-canonical version. For non-www canonical (redirect www to non-www):
# In vhconf.conf rewrite section
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com$1 [R=301,L]
For www canonical (redirect non-www to www):
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L]
Step 3: DNS Configuration
Ensure both versions resolve:
| Type | Name | Value |
|---|---|---|
| A | @ | YOUR_SERVER_IP |
| CNAME | www | example.com |
Step 4: Cloudflare Page Rules (If Using Cloudflare)
If using Cloudflare, add a Page Rule for the redirect instead of doing it at the OLS level:
- URL:
www.example.com/* - Setting: Forwarding URL (301)
- Destination:
https://example.com/$1
Verify
curl -sI https://www.example.com | grep -i location
# Should show: Location: https://example.com/