Question
How to prevent direct access to a mail subdomain?
By default, the mail.domain.tld subdomain routes to the same place as domain.tld the main domain; however, some users may not want this to happen for a multitude of reasons. One such reason is that if resources on the site are hardcoded to use the domain.tld, visiting the site with mail.domain.tld will present a 404 and not load those resources.
Answer
You can prevent this with one of the following options.
Note: The "domain.tld" is used as an example. You will need to replace this with your real domain.
As mail.domain.tld is an alias to "domain.com", the easiest way to remove this link would be to create a separate subdomain for the mail.domain.tld. This can be done at "cPanel / Domains / Domains".
A redirect can be added manually in the .htaccess file or in cPanel under "cPanel / Domains / Redirects".
An .htaccess redirect can redirect any request from mail.domain.tld to domain.tld instead. The following code could be placed in the document root's .htaccess for the domain:
CONFIG\_TEXT: RewriteEngine on
RewriteCond %{HTTP\_HOST} ^mail.domain.com$ \[OR\] \
RewriteCond %{HTTP\_HOST} ^www.mail.domain.com$ \
RewriteRule ^.\*$ "https://domain.com" \[R=301,L\]
CPANEL_WARN: The "Alias" method is preferable because it does not interfere with or conflict with any other rules that may already exist in the .htaccess. So be aware of this before using the htaccess method.
Comments
0 comments
Article is closed for comments.