new proxy subdomains & redirects

Phylum

Active Member
Apr 20, 2010
33
0
56
I purchased an SSL cert and to keep things simple, email.tld is what the users should be using when configuring mail clients, and is the website they should use to access 'email via the web'.

My objectives

I'll start off by saying the built-in proxy subdomains (webmail, whm, cpanel etc) all worked fine; dns A (and CNAME) records exist as well.

I made some slight modifications to httpd.conf....
Code:
...
ScriptAliasMatch ^/?email/?$ /usr/local/cpanel/cgi-sys/wredirect2.cgi
ScriptAliasMatch ^/?mail/?$ /usr/local/cpanel/cgi-sys/wredirect2.cgi
...

<VirtualHost ip1:80 ip1:443 ip2:443 ip2:80 ip3:443 ip3:80 127.0.0.1:80 *>
    ServerName hostname.tld
    ServerAlias cpanel.* whm.* mail.* email.* webmail.* webdisk.* autodiscover.* autoconfig.*
...
    RewriteCond %{HTTP_HOST} ^email\.
    RewriteCond %{HTTPS} on
    RewriteRule ^/(.*) https://127.0.0.1:2096/$1 [P]
    RewriteCond %{HTTP_HOST} ^mail\.
    RewriteCond %{HTTPS} on
    RewriteRule ^/(.*) https://127.0.0.1:2096/$1 [P]
    RewriteCond %{HTTP_HOST} ^email\.
    RewriteRule ^/(.*) http://127.0.0.1:2095/$1 [P]
    RewriteCond %{HTTP_HOST} ^mail\.
    RewriteRule ^/(.*) http://127.0.0.1:2095/$1 [P]
...
</VirtualHost>
... then created wredirect2.cgi from wredirect.cgi and changed one thing in wredirect2.cgi: webmail to email
Code:
    service => ( $zero =~ /whm/ ? 'whm' : ( $zero =~ /^w|\s+w/ ? 'email' : 'cpanel' ) )

The above works. I tested the 2 new subdomains and it successfully loads the webmail login screen. And of course https://webmail.tld still works. So great, almost there.

To help prevent user confusion due to the domain mismatch SSL warnings, I want to redirect http & https requests for webmail.tld and email.tld to https://email.tld [over port 443].

I was thinking of something like this. But perhaps I should be doing this differently; in a way that doesn't require hard coding the domain into httpd.conf?
Code:
...

<VirtualHost ip1:80 ip1:443 ip2:443 ip2:80 ip3:443 ip3:80 127.0.0.1:80 *>
    ServerName hostname.tld
    ServerAlias cpanel.* whm.* mail.* email.* webmail.* webdisk.* autodiscover.* autoconfig.*
...
    RewriteCond %{HTTP_HOST} ^webmail\.
    RewriteCond %{HTTPS} on
    RewriteRule ^/(.*) https://email.tld/$1 [P]
    RewriteCond %{HTTP_HOST} ^webmail\.
    RewriteRule ^/(.*) http://email.tld/$1 [P]
...
</VirtualHost>