Redirecting from webmail.domain.tld to server's primary https URL

vagrant

Registered
Mar 5, 2012
2
0
51
cPanel Access Level
Root Administrator
I've seen other threads about this general topic, but I didn't find what I needed to know.

We'd like to implement the following behavior:

User goes to webmail.userdomain.tld.
User is redirected to https://www.mainserverdomain.tld:2096


Currently, after setting the tweak settings, www.userdomain.tld/webmail redirects as we want it to, to https://www.mainserverdomain.tld:2096. We want webmail.userdomain.tld to do the same.

But webmail.userdomain.tld redirects to https://webmail.userdomain.tld:2096, which results in a cert error, because we only have a valid cert for mainserverdomain.tld.


Is there a way to achieve this without adding lines to the htaccess files for every user domain or other apache hacks?

Thanks.
 

vagrant

Registered
Mar 5, 2012
2
0
51
cPanel Access Level
Root Administrator
Original poster here. We figured out a way to get the behavior we were looking for:

In WHM -> Server Configuration -> Tweak Settings -> Domains, we turned off Proxy subdomains.

In WHM -> Service Configuration -> Apache Configuration -> Include Editor, we added the following to the Post VirtualHost Include config file (replace SERVER_IP with your IP, of course):

<VirtualHost SERVER_IP:80 *>
ServerAlias webmail.* cpanel.*

# Redirect webmail.domain.tld to domain:2096 for cPanel Webmail only
# And redirect cpanel.domain.tld to domain:2083 for cPanel only
RewriteEngine on
RewriteCond %{HTTP_HOST} ^webmail\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/webmail$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^cpanel\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/cpanel$1 [R=301,L]
</VirtualHost>


Thanks to user fevangelou in this post for the rewrite rules:
http://forums.cpanel.net/f34/soluti...cting-actual-cpanel-webmail-login-167890.html