3 of 3 Clarified wording

cPanel is notoriously bad for managing redirects. (I didn't think you could create HTTP to HTTPS redirects using cPanel alone?)

I do not know if this is possible...

Probably not from cPanel. But this is relatively straightforward in .htaccess (by directly editing the file itself). To be honest, if something of this nature is not possible in .htaccess then it's probably not something you should be doing in the first place.

If you simply want to redirect from HTTP to HTTPS on the same hostname then all you need is something like:

RewriteEngine On

# Redirect HTTP to HTTPS on the same host
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

The HTTP_HOST server variable contains the hostname from the request. eg. example1.com, example2.com, www.example1.com. Note that this alone does not canonicalise the www subdomain.

This is also a 302 (temporary) redirect (the same as simply specifying the R flag by itself). Change to a 301 (permanent) only when you are sure it's working OK. (301s are cached hard by the browser so can make testing problematic.)

To canonicalise the www subdomain and redirect non-www to www then add an additional directive:

RewriteEngine On

# Redirect non-www to www (and HTTPS) on the same domain
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# Redirect HTTP to HTTPS on the same host
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

This does assume that you don't have any other subdomains (other than www) on these domains.

Note that whilst this might at first look like two redirects (since there are two separate directives), only one redirect will result, since the first non-www to www redirect always redirects to HTTPS (so the second redirect would never occur in this case).

No need to repeat RewriteEngine more than once.


The add-ons are not in the public_html folder ...

If the Addon domains do not point to the (main domains) public_html folder, or a subdirectory of the public_html folder then you will need to create a separate .htaccess in the document root for each Addon domain, since they are completely separate entities. The above directives would then work for the Addon domains .htaccess file(s).

However, if the Addon domains point to subdirectories off the main domain's document root (a common default in cPanel's setup). eg. public_html/www.example2.com/. Then the above (single) .htaccess file in the public_html folder would still work...

UNLESS you already have additional .htaccess files (that also use mod_rewrite) in the Addon domain's document root directories. This is because mod_rewrite directives are not inherited by default. Now, depending on your config, you could enable mod_rewrite inheritance (but stress that this would depend on your config and what other directives you already have). Otherwise, you will need to duplicate these directives in the .htaccess file for each Addon domain - the same as above (as if your Addon domains were in different parts of the filesystem).