How to Redirect www to Non-www Without Breaking Your Website
Want your website to use one consistent domain format? Learn how to redirect the www version to the non-www version and avoid common DNS, SSL, and redirect mistakes.
You can have both https://example.com and https://www.example.com point to the same website. But it is usually better to choose one as the preferred version and redirect the other to it. If you want the non-www version to be your preferred URL, visitors who enter the www version should automatically be redirected to the non-www version.
Choose Your Preferred Domain First
Decide which version you want to use: https://example.com or https://www.example.com. Either can work. The important part is consistency. For this guide, we will use https://example.com as the preferred version.
Make Sure Both Hostnames Resolve
Before configuring the redirect, make sure both versions of your domain can reach the correct hosting environment. Your DNS setup needs to support the domain and www hostname according to your hosting provider's requirements. A redirect cannot work correctly if the hostname cannot reach the server handling the redirect.
Make Sure HTTPS Works
Your redirect should ultimately send visitors to the HTTPS version of the preferred domain. You do not want a redirect chain such as http://www.example.com to http://example.com to https://example.com. A cleaner configuration sends visitors directly to the final HTTPS URL where possible.
Configure the 301 Redirect
The exact configuration depends on your server. For Apache, redirects are commonly configured through .htaccess. A typical rule conceptually looks like www.example.com/path redirecting to https://example.com/path. The original path should be preserved. For example, https://www.example.com/about should become https://example.com/about, not simply https://example.com/.
For Nginx, this is commonly handled with a dedicated server block for the www hostname that returns a permanent redirect to the preferred hostname. The exact configuration depends on your server setup. Do not paste an Nginx configuration into an Apache server.
Test the Redirect
After configuring the redirect, test http://www.example.com, https://www.example.com, http://example.com, and https://example.com. The preferred URL should be https://example.com, and the other versions should ultimately redirect there.
Watch for Redirect Loops
A redirect loop happens when the server keeps redirecting the browser between two URLs. For example, www to non-www and then another rule sends non-www back to www. Both rules fight each other. Only one canonical hostname should be selected.
Update Internal Links
Once you select your preferred domain, use it consistently throughout your website. Check navigation links, images, canonical URLs, sitemap URLs, structured data, and social sharing URLs. You do not need to panic about every old link, but keeping internal URLs consistent reduces unnecessary redirects.
Does www or Non-www Rank Better?
Neither format automatically gives you a ranking advantage. The important thing is to choose one and use it consistently. Search engines can understand redirects and canonical signals, but unnecessary duplication and redirect chains are still worth avoiding.
FAQ
Should I use www or non-www?
Either can work. Choose one as your canonical domain and consistently use it.
Is a 301 redirect permanent?
A 301 redirect tells clients and search engines that a URL has permanently moved to another URL.
Can I redirect www using DNS alone?
DNS determines where a hostname resolves. The actual HTTP redirect is normally handled by the web server, hosting platform, CDN, or another redirect service.
Will redirecting www hurt SEO?
A properly implemented redirect generally helps consolidate the preferred URL rather than creating separate versions of the same site.
Why am I getting a redirect loop?
You may have conflicting rules that redirect www to non-www while another rule redirects non-www back to www.
Ready to launch your website?
Deploy your website in minutes with Host Better. Free SSL, custom domains, and instant deployment included.
Start Hosting Now