Choosing between www and non-www for your domain is a personal preference, but you should pick one and redirect the other. This prevents duplicate content issues and ensures all your traffic goes to a single canonical URL.
Add to .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
01. Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
Replace yourdomain\.com with your actual domain (escape the dot with a backslash).
02. Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
03. Combined with HTTPS
To force both HTTPS and www (or non-www) in one rule set:
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force www
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
Put the HTTPS rule first, then the www rule. This avoids double redirects (which are slower and can cause issues with some browsers). For the HTTPS redirect, you can also use cPanel's Force HTTPS toggle. See HTTP to HTTPS Redirect.
If redirects are not working or causing loops, see Nginx and .htaccess Redirect Issues. For the complete .htaccess reference, see .htaccess Guide.
Redirect Issues?
Open a Support TicketQuick Recap
- Pick www or non-www and redirect the other
- Use 301 redirects for permanent changes
- Combine with HTTPS in the same .htaccess
- HTTPS rule first, then www rule
- Test in incognito - Browsers cache 301 redirects
URL canonicalization · Last updated March 2026 · Browse all htaccess articles
