Forcing .cpanel .whm and .webmail subdomains to server hostname w/ SSL

jrquint

Registered
Mar 30, 2012
3
0
51
cPanel Access Level
Root Administrator
We've had quite a few customers get accustomed to accessing their accounts via the cpanel.(domain.com) and webmail.(domain.com). For obvious reasons we force SSL on these subdomains (tweak settings) as they're passing login information through them. The issue with this is that they all get certificate errors as cPanel will use the server's hostname SSL certificate. This worries quite a few users and we've gotten a few complaints.

Since I don't see any option to have the subdomains redirected to the HOSTNAME.com:2083, etc in tweak settings (like you can do for domain.com/cpanel) came up with this procedure to modify the httpd.conf to force this redirect:



# cp /var/cpanel/templates/apache2_4/main.default /var/cpanel/templates/apache2_4/main.local

# nano /var/cpanel/templates/apache2_4/main.local

replace (2 locations) :

RewriteEngine On
RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^cpanel\.
RewriteRule ^/(.*) http://127.0.0.1:2082/$1 [P]

RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^webmail\.
RewriteRule ^/(.*) http://127.0.0.1:2095/$1 [P]

RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^whm\.
RewriteRule ^/(.*) http://127.0.0.1:2086/$1 [P]

with:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^webmail\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.webmail\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2096" [R=301,L]

RewriteCond %{HTTP_HOST} ^cpanel\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.cpanel\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2083” [R=301,L]

RewriteCond %{HTTP_HOST} ^whm\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.whm\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2087” [R=301,L]

rebuild httpd.conf and restart apache:

# /scripts/rebuildhttpdconf
# /etc/init.d/httpd restart
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello :)

Thank you for sharing this workaround. Please note that user-submitted workarounds are not tested or supported by cPanel. We encourage everyone to review all aspects of workarounds before implementing them on a production server.

Thank you.