H-Sphere 3.1 CP Custom Templates & mod_rewrites

Custom Templates
In the process of upgrading to H-Sphere to version 3.1, we decided to correctly handle the custom templates. Unfortunately, the documentation (available here), doesn’t have the correct information on how to run the configuration. After some digging, we found the right binary to run! So, to do the custom templates, follow the instructions until it mentions the ‘apache_restart’ command. Since that doesn’t exist, run the following:

/hsphere/local/home/cpanel/apache/bin/conf_httpdcp

And then restart the httpdcp apache instance:

/etc/init.d/httpdcp restartapache

And there you have it – a custom config. Hopefully it will stay over the next reboot.

mod_rewrites
We also wanted to handle the mod_rewrite rules in our custom config, so it would redirect to port 443 for the typical other ports opened on the cp (we have 80, 8080, and 8443 open to accommodate some of our customers, and it’s just convenient). Here are the additional rules we add:

<VirtualHost _default_:80>
      RewriteEngine on
      RewriteCond ${HTTPS} !on
      RewriteRule ^/(.*)$ https://cp.htgwebhome.com:443 [R=permanent,L]
</VirtualHost>

<VirtualHost _default_:8080>
      RewriteEngine on
      RewriteCond ${HTTPS} !on
      RewriteRule ^/(.*)$ https://cp.htgwebhome.com:443 [R=permanent,L]
      RewriteCond ${SERVER_PORT} !^443$
      RewriteRule ^/(.*)$ https://cp.htgwebhome.com:443 [R=permanent,L]
</VirtualHost>

We wrestled with getting port 8443 to redirect, and never succeeded, and we’re okay with that. The rules seem weird, but that’s what got it to work for us, so we kept them!

Leave a Reply