Add a permanent 301 redirect on your server or CDN that sends every request for example.com to the same path on www.example.com. Keep the path and query string, force HTTPS in the same hop, and make sure your certificate covers both hostnames. Then test with curl to confirm one hop and a 301 status.
Why it matters
A 301 redirect tells browsers and search engines that the move is permanent, so links and signals for the old address consolidate on the new one. Without it, both versions of every page can load, which splits your link value and clutters Search Console reports.
How to do it
- Make sure DNS for both example.com and www.example.com resolves to your server or CDN, and that your HTTPS certificate lists both names.
- Add the rule for your server. For Apache in
.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
- For nginx, add a separate server block for the bare domain:
server {
listen 80;
listen 443 ssl;
server_name example.com;
# certificate lines for example.com go here
return 301 https://www.example.com$request_uri;
}
- For ASP.NET Core, a small middleware can compare
Request.Hostwith the wanted host and issueResponse.Redirect(url, permanent: true). Behind a proxy, read the forwarded host headers first. - If you use a CDN or hosting panel, look for a redirect rule or a "redirect to www" setting and choose a permanent (301) type.
- Test every variant:
curl -sI http://example.com/some/page?x=1
curl -sI https://example.com/some/page?x=1
Each response should show 301 and a location header that already starts with https://www.example.com/. If the first hop goes to http://www and a second hop goes to https, combine them into one rule.
7. Update canonical tags, the sitemap and internal links to the www address, then add or check the www property in Google Search Console.
Common mistakes
- Redirecting only the home page, so deep pages still load on the bare domain.
- Dropping the path or query string, which sends everyone to the home page.
- Creating a loop by also redirecting www back to non-www in a CMS setting or plugin.
- Using a 302 or meta refresh instead of a server-side 301.
- Letting an HTTPS certificate cover only one hostname.
Frequently asked questions
Will the redirect cost me rankings?
A correct 301 is the normal way to consolidate two hostnames and Google follows it. Short-term fluctuation can happen on an existing site, so make the change once and avoid repeating it.
Do I still need canonical tags?
Yes, keep them. The redirect handles visitors and crawlers that request the bare domain, while the canonical tag confirms the preferred address on the pages themselves.
How long should the redirect stay?
Leave it in place permanently. Old links, bookmarks and printed addresses will keep using the old form for years.
Related guides
- WWW vs non-WWW: choose one canonical host and redirect the other
- Nginx and Apache redirects for SEO
- ASP.NET Core SEO redirects and HTTPS
- Redirect chains and loops
Crawvix's scan checks for one canonical host. Try the free website sample to test your own redirects.