Introduction
Htaccess Redirect to www ensures your website has a consistent domain format. Search engines treat www.example.com and example.com as separate URLs unless redirected, which can split SEO value.
Htaccess Redirect to www Example
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
How It Works
The condition checks if the URL does not start with www. If not, it redirects the user permanently (301) to the www version, consolidating link equity and preventing duplicates.
Why Use This?
Canonicalizing your domain with Htaccess Redirect to www prevents duplicate indexing, consolidates backlinks, and strengthens your SEO signals.
Common Mistake
Forgetting to use a 301 permanent redirect may confuse search engines and dilute page authority.
Pro Tip
If you prefer non-www, simply reverse the condition and redirect all traffic from www to non-www. Always test carefully to avoid redirect loops.