I want /webmail gone!

jspierre

Member
Mar 3, 2011
5
0
51
I've searched for the answer to this, but I can't seem to find anything specific. Here's what I want to do:

I want to completely remove the /webmail ability for all domains on the server. By default, this points to cPanel's webmail login, but I do not want this available to any domain. So, I need http://www.mydomain.com/webmail and https://www.mydomain.com/webmail to DO NOTHING (except return a "404 Not Found" error).

I realize that, once this is done, you can still get to the webmail interface using the port numbers (mydomain.com:2095, etc.); that's fine and I want to leave that alone. The only thing I'm concerned about is the /webmail URL. I want that special redirection to be removed.

How can I do this? Can this be done?

Any help would be appreciated!
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
First of all, ensure that WHM > Tweak Settings has these all set to "Off":

Proxy subdomains [?]

Add proxy VirtualHost to httpd.conf to automatically redirect unconfigured cpanel, webmail, webdisk and whm subdomains to the correct port (requires mod_rewrite and mod_proxy)

Proxy subdomain creation [?]

Automatically create cpanel, webmail, webdisk and whm proxy subdomain DNS entries for new accounts. When this is initially enabled it will add appropriate proxy subdomain DNS entries to all existing accounts. (Use /scripts/proxydomains to reconfigure the DNS entries manually)

Proxy subdomain override [?]

Allow users to create cpanel, webmail, webdisk and whm subdomains that override automatically generated proxy subdomains
Next, you are going to have to modify the template file to remove the option for webmail in it:

Code:
cp /var/cpanel/templates/apache2/main.default /var/cpanel/templates/apache2/main.local
vi /var/cpanel/templates/apache2/main.local
You'll need to change these lines:

Code:
ErrorLog [% main.errorlog.item.errorlog %]
DefaultType [% main.defaulttype.item.defaulttype %]
[% FOREACH dir IN main.scriptaliasmatch.items -%]
ScriptAliasMatch [% dir.regex %] [% dir.path %]
[% END -%]
To these lines:

Code:
ErrorLog [% main.errorlog.item.errorlog %]
DefaultType [% main.defaulttype.item.defaulttype %]
ScriptAliasMatch ^/?controlpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
ScriptAliasMatch ^/?cpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
ScriptAliasMatch ^/?kpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
ScriptAliasMatch ^/?securecontrolpanel/?$ /usr/local/cpanel/cgi-sys/sredirect.cgi
ScriptAliasMatch ^/?securecpanel/?$ /usr/local/cpanel/cgi-sys/sredirect.cgi
ScriptAliasMatch ^/?securewhm/?$ /usr/local/cpanel/cgi-sys/swhmredirect.cgi
ScriptAliasMatch ^/?whm/?$ /usr/local/cpanel/cgi-sys/whmredirect.cgi
This yanks out this line that normally builds into Apache's /usr/local/apache/conf/httpd.conf configuration file:

Code:
ScriptAliasMatch ^/?webmail/?$ /usr/local/cpanel/cgi-sys/wredirect.cgi
After making that change, make a backup copy of Apache's configuration, rebuild it and restart it:

Code:
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak110303
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
If you then check grep for webmail in the file, it shouldn't return anything in the file any longer:

Code:
grep -i webmail /usr/local/apache/conf/httpd.conf
Of note, by changing the main.default file to main.local, you are bypassing the cPanel updates for main.default happening any longer. Your Apache will begin only using the template main.local you have. This means that if we drastically modify main.default at some point in the future, your Apache configuration file will be out of date. This is something to keep in mind when changing the templates such as this would do.