Your website can be reached at both example.com and www.example.com. Search engines treat those as two addresses, so it's best to pick one and redirect the other to it. This guide shows you how to redirect www to non-www (or non-www to www) safely, together with HTTPS.
Which should I choose?
Either is fine. Google doesn't prefer one over the other. What matters is that you pick one and stick with it:
- Non-www (
example.com) is shorter and common for newer sites. - www (
www.example.com) is traditional. If your site already uses it and ranks well, keep it.
If your site has been live for a while, use whichever version Google already shows in search results.
WordPress sites: set it in WordPress first
WordPress redirects to the address stored in its settings. If that address doesn't match your redirect, you can get an endless redirect loop.
- Log in to WordPress admin. See How to Log In to WordPress Admin from WP Toolkit.
- Go to Settings > General.
- Set both WordPress Address (URL) and Site Address (URL) to your chosen version, for example
https://example.com. - Click Save Changes. You'll be logged out and asked to log in again at the new address.
WordPress will now send visitors from the other version to your chosen one. You can still add the .htaccess rule below so the redirect happens a step earlier and also covers HTTPS.
How to redirect www to non-www with .htaccess
This works for any website, including WordPress. It forces both HTTPS and your chosen version in one redirect.
- In cPanel, go to Files > File Manager.
- Open the
public_htmlfolder. If you don't see.htaccess, click Settings in the top right, tick Show Hidden Files (dotfiles) and click Save. See How to Show Hidden Files (.htaccess) in cPanel File Manager. - Right-click
.htaccessand choose Edit. (If there's no.htaccessfile, click + File and create one named.htaccess.) Before editing, it's a good idea to download a copy as a backup. - Add the following at the very top of the file, above any
# BEGIN WordPresssection, replacingexample.comwith your domain:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
- Click Save Changes.
How to redirect non-www to www with .htaccess
Follow the same steps but use this block instead:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Note the backslash before each dot in the RewriteCond line. Keep those in.
Test your redirect
Open a private/incognito browser window and try all four versions of your address:
http://example.comhttp://www.example.comhttps://example.comhttps://www.example.com
Every one should end up at your chosen address with a padlock. A private window matters because browsers remember old 301 redirects.
Troubleshooting
"Too many redirects" (ERR_TOO_MANY_REDIRECTS)
- On WordPress, the addresses in Settings > General must match the version your
.htaccessrule redirects to. - Check Domains > Redirects for an old redirect that sends the domain back the other way, and delete it.
- Make sure you added only one of the two blocks above, not both.
- If you can't get into WordPress admin, remove the lines you added from
.htaccess, save, and try again.
The www version shows a certificate warning
The free SSL certificate covers www only when the www name points to the Instant Access Internet Services server. Check Security > SSL/TLS Status to see whether www.example.com is covered. See Free SSL Certificates: How AutoSSL and SSL/TLS Status Work.
Can I use the cPanel Redirects page instead?
The Redirects tool is meant for sending one page or domain to a different address. Using it to redirect a domain to a version of itself can easily create a redirect loop, so we recommend the .htaccess method above.
Related guides
- How to Force HTTPS on Your Website
- How to Set Up a 301 Redirect in cPanel
- Free SSL Certificates: How AutoSSL and SSL/TLS Status Work
- How to Show Hidden Files (.htaccess) in cPanel File Manager
- How to Edit a File in cPanel File Manager
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
