WWW or Non-WWW: How to Redirect Your Domain

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.

  1. Log in to WordPress admin. See How to Log In to WordPress Admin from WP Toolkit.
  2. Go to Settings > General.
  3. Set both WordPress Address (URL) and Site Address (URL) to your chosen version, for example https://example.com.
  4. 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.

  1. In cPanel, go to Files > File Manager.
  2. Open the public_html folder. 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.
  3. Right-click .htaccess and choose Edit. (If there's no .htaccess file, click + File and create one named .htaccess.) Before editing, it's a good idea to download a copy as a backup.
  4. Add the following at the very top of the file, above any # BEGIN WordPress section, replacing example.com with your domain:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
  1. 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.com
  • http://www.example.com
  • https://example.com
  • https://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 .htaccess rule 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

Still stuck? Open a support ticket and the Instant Access Internet Services team will help.

Ultrafast LiteSpeed hosting from InstantAccess.net: free SSL, free backups, cPanel included, no contracts. Check out our $10/month hosting.
  • redirect www to non-www, redirect non-www to www, htaccess www redirect, cpanel www redirect, canonical domain redirect, wordpress www or non-www
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Use Microsoft 365 or Google Workspace Email with Your Domain

You can keep your website with us and use Microsoft 365 (Outlook) or Google Workspace (Gmail) for...

Our Nameservers: How to Point Your Domain to Your Hosting

To make your website and email work on your hosting account, your domain has to point to the...

DNS Propagation: Why Domain Changes Take Time and How to Check

When you change your nameservers or edit a DNS record, some people see the change right away...

How to Set Up Dynamic DNS in cPanel

Dynamic DNS (DDNS) lets you reach a device on a home or office connection, such as a camera, NAS...

Free SSL Certificates: How AutoSSL and SSL/TLS Status Work

Every hosting account includes free SSL certificates, so your website loads over HTTPS with a...