How to Force HTTPS and Redirect www to non-www (or non-www to www)
After installing an SSL certificate, your website can still open over plain http:// and under two different addresses (with and without www). This splits your SEO signals and can show "Not secure" warnings. This guide explains how to force HTTPS and redirect www to non-www (or the opposite) using cPanel, .htaccess rules that work on Apache and LiteSpeed, and the WordPress settings, plus how to fix mixed-content warnings.
Before you start
- Make sure your domain has a valid SSL certificate. If not, follow how to get a free SSL certificate (AutoSSL) first. Forcing HTTPS without a valid certificate will show a browser security error.
- Decide which version you want as your main address:
https://example.comorhttps://www.example.com. Both are fine for SEO; what matters is choosing one and redirecting the other to it. - Take a copy of your current
.htaccessfile before editing it.
Method 1: Force HTTPS from cPanel (easiest)
- Log in to cPanel (see how to log in to cPanel).
- In the Domains section, click Domains.
- Find your domain in the list and turn on the Force HTTPS Redirect toggle.
- Open your site using
http://to confirm it now redirects tohttps://.
If the toggle is greyed out, the domain usually does not have a valid SSL certificate yet. This option handles HTTPS only; to choose www or non-www, use the .htaccess rules below.
Method 2: Force HTTPS with .htaccess
- Open File Manager in cPanel and go to your site folder (usually
public_html). - Click Settings (top right) and enable Show Hidden Files (dotfiles) so that
.htaccessis visible. - Right-click
.htaccessand choose Edit (create the file if it does not exist). - Add the following rules at the very top of the file, before the
# BEGIN WordPressblock if you use WordPress:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Method 3: HTTPS + redirect www to non-www
Use this if your main address is https://example.com:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]Method 4: HTTPS + redirect non-www to www
Use this if your main address is https://www.example.com:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]These rules redirect every variation to your chosen address in a single 301 (permanent) redirect, which is the best option for SEO. LiteSpeed servers read .htaccess rules the same way as Apache, so the same code works on EgWeb hosting.
.htaccess, or install an extra redirect plugin, you may get redirect loops or extra redirect hops. Test in a private browser window because browsers cache 301 redirects.Update the WordPress Address settings
- In the WordPress dashboard go to Settings > General.
- Change WordPress Address (URL) and Site Address (URL) to your final address, for example
https://example.com(same www choice as your redirect). - Click Save Changes. You will be logged out and asked to log in again on the new address.
If these fields are greyed out, they are defined in wp-config.php as WP_HOME and WP_SITEURL; edit them there.
Fix mixed content warnings
Mixed content happens when an HTTPS page loads images, scripts or styles over http://. The browser then shows a broken padlock or blocks the files.
- Open the page, press F12 and check the Console tab for "Mixed Content" messages to see which files are loaded over HTTP.
- In WordPress, use a search-and-replace plugin (such as Better Search Replace) to replace
http://example.comwithhttps://example.comin the database. Take a backup first. - Check your theme settings, page builder, widgets and custom code for hard-coded
http://links. - Clear your cache plugin (for example LiteSpeed Cache) and your browser cache, then test again.
Common problems
- "Too many redirects" (ERR_TOO_MANY_REDIRECTS): usually two redirect methods conflict, or the site is behind a proxy/CDN such as Cloudflare set to "Flexible" SSL. Remove duplicate rules and set the CDN SSL mode to "Full".
- 500 Internal Server Error after editing .htaccess: there is a typo in the rules. Restore your backup copy and paste the rules again carefully. See how to fix a 500 Internal Server Error.
- Certificate warning on www: the SSL certificate does not cover the www version. Make sure the
wwwDNS record points to your hosting and run AutoSSL again. - Redirect does not work for subfolders or addon domains: each addon domain or subfolder installation may have its own
.htaccess; add the rules there too.
Frequently asked questions
Is www or non-www better for SEO?
Neither is better. Choose one, redirect the other to it with a 301 redirect, and use the same version everywhere (WordPress settings, sitemap and Google Search Console).
Will forcing HTTPS affect my Google ranking?
A correct 301 redirect passes your ranking signals to the HTTPS address. HTTPS is also a positive signal for Google and increases visitor trust.
Do I still need a plugin to force HTTPS in WordPress?
No. The cPanel toggle or the .htaccess rules plus the WordPress Address settings are enough. A plugin is only helpful for fixing stubborn mixed content.