Redirect HTTP to HTTPS and choose www or non-www in cPanel
To force HTTPS, open cPanel, go to Domains, and turn on the Force HTTPS Redirect option for your domain. To choose between www and non-www, use a redirect rule in .htaccess and adjust the address under Settings > General in WordPress. The goal is for the site to have a single final address, always secure, and for every other variation to lead to it.
This article covers both routes (the control panel and .htaccess), how to test them, and what to do if the site starts showing a redirect error. cPanel menu names may vary depending on the version and theme of the panel. If something does not appear with the name given here, look for a similar item or contact support.
Before you start: the certificate must be active
Forcing HTTPS without a valid certificate shows visitors a security alert screen. At MigraCloud, SSL is Let’s Encrypt, issued and renewed automatically. Before enabling any redirect, open https://yourdomain.com and https://www.yourdomain.com and confirm that both load with a padlock. If either one shows a warning, see How to install SSL in cPanel or ask support about the status of the certificate.
Step 1: force HTTPS through cPanel
This is the simplest route, and the one that puts the site at the least risk.
- Log in to cPanel and open Domains.
- Find your domain in the list.
- Turn on the Force HTTPS Redirect toggle.
- Test the address with
http://in an incognito window.
If the option does not appear in your account, use .htaccess. If you have already enabled the cPanel option, you do not need the rule from Step 2.
Step 2: force HTTPS through .htaccess
The .htaccess file is in the main folder of the site (usually public_html). It is a hidden file: in the cPanel File Manager, turn on the display of hidden files in the settings.
Before editing, make a copy of the file (for example, .htaccess-copy). A typo can take the site down with a 500 error, and the copy lets you undo the change right away. If the file does not exist, see .htaccess in WordPress: how to find and create the default file.
Paste the block below at the top of the file, above the # BEGIN WordPress section:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
Do not delete or change the WordPress section, and do not repeat rules that are already in the file. Two rules sending traffic to the same place, or one contradicting the other, are the main cause of redirect loops.
Step 3: choose www or non-www
For Google and for visitors, yourdomain.com and www.yourdomain.com are different addresses. If both open the site without redirecting, you will have two versions of the same content. Pick one and redirect the other. There is no right version: what matters is consistency.
To always use non-www, add this to .htaccess, next to the HTTPS rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
To always use www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your domain. These rules already send visitors to https://, so if you use one of them, it is still a good idea to keep the Step 2 rule, to cover anyone who types http:// in the right address.
If you prefer the control panel route, cPanel also has the Redirects tool, which includes an option for how www behaves. See How to redirect a domain in cPanel.
Step 4: set the address in WordPress
WordPress also needs to know the official address.
- In the WordPress dashboard, go to Settings > General.
- In WordPress Address (URL) and Site Address (URL), enter the version you chose, starting with
https://and with or withoutwww, matching what you set in the rules. - Save. WordPress will ask you to log in again.
Both fields must match the redirect. If one says www and the rule sends traffic to the address without www, the site will enter a loop. If the fields are locked, the addresses are fixed in the wp-config.php file.
Step 5: test
Use an incognito window to avoid cache and extensions. 301 redirects are stored by the browser, and an old result can be misleading.
| Address typed | Expected result |
|---|---|
http://yourdomain.com |
Goes to the chosen version, at https:// |
http://www.yourdomain.com |
Goes to the chosen version, at https:// |
https://yourdomain.com |
Opens, or goes to the www version, depending on your choice |
https://www.yourdomain.com |
Opens, or goes to the non-www version, depending on your choice |
Also check an inner page. If the padlock shows a warning, the cause is usually mixed content: see WordPress without a padlock after SSL: mixed content.
Risk: redirect loop
If the browser shows “too many redirects” or “this page isn’t working,” some rule is sending the visitor from one address to another endlessly. The most common causes are:
- the same rule in
.htaccessand in a plugin; - Settings > General with a different
wwworhttpsthan the redirect; - the cPanel option and the manual rule competing for the same task;
- a CDN or proxy service in front of the site with an incompatible SSL mode.
Restore the .htaccess copy you saved and reapply one rule at a time, testing between each one. The full diagnosis is in Too many redirects error in WordPress.
SEO: keep one canonical version
For search engines, different addresses with the same content split the strength of the page. So:
- redirect with 301 (permanent), as in the rules above;
- use the same version in the WordPress address, in the sitemap, and in internal links;
- if you use an SEO plugin, check that the canonical address follows the version you chose;
- add the final version to Google Search Console.
Frequently asked questions
Which is better: with www or without www?
For SEO, neither. The difference is only one of preference and configuration. Pick one, redirect the other, and keep your choice consistent everywhere.
Is the cPanel “Force HTTPS Redirect” option enough?
To send visitors from http:// to https://, yes. It does not decide whether the address will include www. For that, use a rule in .htaccess or the Redirects tool.
I edited .htaccess and the site gave a 500 error. What now?
Restore the copy you made before editing. If you did not make one, JetBackup, which creates automatic backups, lets you restore the file yourself. If you have questions, support can guide you.
The site opens, but there is still no padlock. What could it be?
Most likely there is mixed content: images, scripts, or styles still being loaded over HTTP. See the article on mixed content in WordPress.