Domains and DNS

Choose the www or non-www version and redirect the other

Reviewed on 2 min read redirects www

Choose a main version of the domain and make the other one lead to the same page. Before changing anything, check that both names resolve to the right server and have a valid certificate.

If WordPress, PrestaShop or another application already sends visits to its configured URL, make a choice that matches it. Opposing rules between the application, cPanel and a proxy can create a loop.

From example.com to www.example.com

In cPanel > Redirects:

  1. Select the origin domain.
  2. Use Temporary (302) while you check the result; switch to Permanent (301) when the decision is final.
  3. Enter https://www.example.com/ as the destination, replacing the name with yours.
  4. Choose Do Not Redirect www. so the destination name is not redirected again.
  5. Turn on Wild Card Redirect to keep paths, and save.

If you need to set it up manually, the equivalent for testing in the root .htaccess is:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=302,L]

From www.example.com to example.com

Use the destination without www and select Only redirect with www.. Do not also keep the rule in the opposite direction. The manual example would be:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=302,L]

Check and maintain

Test the home page, an internal page and a URL with parameters. Check that they reach the equivalent content and that the chosen version does not redirect back to the other. Once validated, use 301 if the change is permanent.

Save a copy before editing .htaccess. If the CMS's rules run first, review their order and place the custom redirect outside the block the CMS regenerates. Also update the application's URL, its links and its canonical where appropriate.

A permanent redirect helps consolidate the chosen address, but it does not guarantee rankings or immediate results. To undo a mistake, remove that specific rule and test without an old redirect in the browser cache.

You may also find useful

Something wrong or out of date? Tell us and we will review it.