Domain redirects: one address with or without www
Domain redirects serve two purposes: sending visitors to another site, or merging different spellings of the same site (example.com and www.example.com) into one address.
Why pick a single address?
Reaching the same content from two addresses makes search engines see duplicated content. Choose a main address and redirect the other one to it permanently (301).
Ways to redirect
- At DNS level: create a CNAME or A record for www so that the www address reaches your site.
- At server level (.htaccess): on Apache servers you write a redirect rule. Example:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]andRewriteRule ^(.*)$ https://example.com/$1 [R=301,L] - Provider feature: some providers offer a feature to forward a domain to another address.
301 vs 302
301 is a permanent redirect; search engines treat the new address as the main one. 302 is temporary and suits short-term use.
Testing
Try the redirect in a browser and check the output of curl -I http://www.example.com for the 301 status and the Location line.
Thanks for your feedback!