Domains and DNS
Choose the www or non-www version and redirect the other
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:
- Select the origin domain.
- Use Temporary (302) while you check the result; switch to Permanent (301) when the decision is final.
- Enter
https://www.example.com/as the destination, replacing the name with yours. - Choose Do Not Redirect www. so the destination name is not redirected again.
- 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
- Load another website in an iframe Shows how to load another website inside an iframe while keeping the visible domain, which file to c...
- Redirect a domain while keeping certain folders Provides ModRewrite rules to move a domain to another address without affecting an intranet or other...
- Redirect a domain without ordering hosting Shows how to send a domain without hosting, a specific path or all its URLs to another destination f...
- Redirect secondary domains to a main domain Explains how to point several secondary names to the main one using DNS and redirects in the current...
Something wrong or out of date? Tell us and we will review it.