Install Wildcard SSL Certificates – cPanel

Posted: March 21, 2014 in cPanel

Before installing this certificate, you should make sure the wildcard subdomain (*.domain.com) has been created in the control panel as well. This is required for proper functioning and installation of the SSL certificate.

Normally customers want their SSL configuration to look something like this:

https://mydomain.com => /home/user/public_html
https://order.mydomain.com => /home/user/public_html/order
https://billing.mydomain.com => /home/user/public_html/billing

We can setup only one SSL virtual host per IP address. However, we can mimic this behavior by using mod_rewrite rules. Here are the steps:

1) Install the wildcard SSL certificate as you normally do so the DocumentRoot is/home/user/public_html/ and the ServerName is *.domain.com.

2) Setup the following mod_rewrite rules in their .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/sub.domain.folder/
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ /sub.domain.folder/$1 [NC,L,NS]

* NC is nocase of course, unnecessary with a .* match but is inserted for paranoia sake.
* L is ‘last’ which stops rewriterule processing on match
* NS is ‘no subrequest’ which keeps internal URI’s from being reprocessed. This may help or break things and would require testing. Look for flash applets or javascripts that don’t load.

** If you are seeing 404 not found errors after adding these rules, check the errors and the path that the connection is trying to take. If you are seeing that the connections are forcing to an addon directory and not redirecting to the subdomain directory, you may need to add a symlink in the addon directory pointing to the subdomain directory due to the redirects not being able to escape doc root.For Example:

 [error] [client xx.xx.xx.xx] File does not exist: /home/my/public_html/subdomain.com/somefile

ln -s /home/my/public_html/sub.subdomain.com/ /home/my/public_html/subdomain.com/

3) Clear all of your browser cache and try accessing the subdomains.

Leave a comment