Skip to content

Permanent redirect to https by using .htaccess

Updated 1 min read

Updated: 28 September 2026 · Applies to: cPanel & WHM 138 (Jupiter theme)

These rules send every visitor to one address, https://www.yourdomain.com, so search engines see a single version of your site (no duplicate http/https or www/non-www copies).

Add to .htaccess

Put this at the top of the .htaccess file in public_html:

RewriteEngine On
# http -> https, and add www in the same step
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]

To use the address without www instead:

RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

Note: The domain needs a valid SSL certificate for both names. Set the same address in your application (for example WordPress Settings › General), and test in a private window.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket