Question
How to prevent direct access to a mail subdomain?
By default, the mail.domain.com subdomain routes to the same place as domain.com 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.com, visiting the site with mail.domain.com will present a 404 and not load those resources.
Answer
You can prevent this with one of the following options.
Note: The "domain.com" is used as an example. You will need to replace this with your real domain.
-
Option 1: Create a subdomain to override the mail alias.
As
mail.domain.comis an alias to "domain.com", the easiest way to remove this link would be to create a separate subdomain for themail.domain.com. This can be done at "cPanel / Domains / Domains". -
Option 2: Create a redirect to redirect the mail domain request in the htaccess file. A redirect can be added manually in the .htaccess file or in cPanel under "cPanel / Domains / Redirects".
Add a redirect. A
.htaccessredirect can redirect any request frommail.domain.comtodomain.cominstead. 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 1st 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 2nd method.
Comments
0 comments
Article is closed for comments.