Skip to content

Forcing HTTPS site-wide on cPanel — the right Apache redirect

The correct cPanel-side HTTPS redirect that does not break /.well-known/, mixed content, or shared resources, plus the WHM toggle that does most of the work.

Force HTTPS is one toggle in cPanel, but operators still write custom redirect rules because the toggle does not cover every case (subdomains added later, mail subdomains, ACME paths). Here’s the rule that actually works, and what the cPanel UI handles for you.

What’s happening

cPanel exposes a per-domain HTTPS-redirect setting at cPanel > Domains > Force HTTPS Redirect. When toggled, cPanel writes an .htaccess rewrite that redirects every HTTP request to HTTPS, with one important exclusion: /.well-known/acme-challenge/ is exempted, so AutoSSL still works. The rule is per-domain; subdomains added later get the redirect only if the toggle is on for that subdomain.

How to verify

curl -I http://example.com/
curl -I http://www.example.com/
curl -I http://example.com/.well-known/acme-challenge/test
grep -E "RewriteCond|RewriteRule" /home/<user>/public_html/.htaccess | head
whmapi1 fetch_domains user=<user>

A correct setup returns 301 Moved Permanently to the HTTPS URL for the first two, and either a 200 or 404 (but not a redirect) for the third.

The fix

  1. First choice — use the cPanel toggle: cPanel > Domains > Force HTTPS Redirect for each domain. This is the supported path. It handles the well-known exemption.
  2. Confirm subdomain coverage: every subdomain has its own toggle. If blog.example.com was added after the apex toggle was set, set it explicitly.
  3. If you need a hand-written rule (custom vhost include), use this in the per-account .htaccess:
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  4. Do not use https://example.com/$1 with a hard-coded hostname — the %{HTTP_HOST} form survives multi-domain accounts.
  5. Mixed content: after redirect is on, audit pages for HTTP-loaded scripts, images, and iframes. Browsers will block them. Either fix the URLs or set a Content-Security-Policy that upgrades insecure requests.
  6. Mail subdomain: mail.example.com does not need force-HTTPS for SMTP/IMAP/POP3 — those use their own TLS on different ports. Webmail does benefit from HTTPS-only; that toggle is in the same place.
  7. After-redirect verification: check that internal links in WordPress/customer apps point at HTTPS. Some CMSes hard-code the home URL.

Stack Harbor enforces HTTPS-only across managed accounts as part of cPanel server management.