How to change / remove cPanel default website page for mail.domain.com?

5,276

Connect via FTP to your website, go to the document root, and create, or edit, the file called .htaccess. Your document root should contain either index.php or index.html file. That's how you know it's the document root. If the file exists, edit it. Otherwise, create it.

Now, edit that file, and make sure you have the following content. Some lines may already be there. Add this content at the end. If it already contains RewriteEngine On - dont touch it and just add the next 2 out of 3 lines below:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mail\..*$ [NC]
RewriteRule ^.* - [F]

The first line enables the RewriteEngine. The second line specifies that the RewriteRule will work only if the domain starts with mail.. The final line, takes any request, and sends the 403 - Forbidden HTTP status message.

This should work fine if the server used is Apache HTTPD, however if others, like nginX are used, you'd have to look how to do the same with them. For nginX, it would be something like this:

if ($host ~* ^mail\..*$ ) {
    return 444;
}

Sending a non-standard, 444 status, causes the connection to close, without sending any response. Alternatively you could send 403 if you want a "Forbidden" status.

Unfortunately I can't vouch for nginX since I've never used it. Maybe you'd need to write that to a different file or something. I don't know. But you probably have Apache HTTPD there.

Also, this question belongs on either stackoverflow.com, or serverfault.com.

Share:
5,276

Related videos on Youtube

Mina Hafzalla
Author by

Mina Hafzalla

Updated on September 18, 2022

Comments

  • Mina Hafzalla
    Mina Hafzalla over 1 year

    I have this default page showing up every time I visit mail.mydomain.com.

    Here is a screenshot.

    cPanel default website page

    I don't want this page to show up like that or even show up at all. How can I prevent it from showing up, so any visitor won't be able to see the default website page message.

    My website running on VPS WHM/cPanel, CentOS 6.5 64-bit.

    I contacted my hosting provider and they said:

    "This is normal as, mail.domain.com is a 'cname' for your domain and is needed for your email to work correctly. Unfortunately changing this page would be custom configuration (branding) that is outside of our scope of managed support"

  • Mina Hafzalla
    Mina Hafzalla about 10 years
    It didn't work :( , I posted an edit to my question. Please see it and tell me If I placed the code in a wrong way. Thank you very much.
  • Arjan
    Arjan about 10 years
    @MinaIsaac, why did you change the RewriteRule? (Your version would only work for the URLs like http://mail.mydomain.com/mydomain.com.) And what does "it does not work" mean? No changes, or some error?
  • Arjan
    Arjan about 10 years
    The page in the screenshot is just the default cPanel page, which apparently has not been changed by the hosting company. I quickly checked two cPanel accounts on the very same server: one shows the site's default index.html for any subdomain, while the other shows that default cPanel page instead. I couldn't quickly find any differences in related cPanel configurations, and I doubt DNS settings could be the culprit. Too bad that /usr/local/cpanel/cgi-sys/defaultwebpage.cgi is a compiled file, making it hard to see what it does exactly.
  • Alex
    Alex about 10 years
    @MinaIsaac, if you want a more specific RewriteCond, then use this: ^mail\.mydomain\.com$ instead of what you used (though I wouldn't be so speciffic. At least don't put the dollar $ sign at the end). And you changing the RewriteRule caused it not to work. Leave it to ^.*. If the RewriteCond passes, then you already have a request to mail.mydomain.com. Any such request should be forbidden. Don't try to insert any more rules there. Especially that RewriteRule only checks the trailing path (ex. /images/house.jpg). It does not contain the domain.
  • Mina Hafzalla
    Mina Hafzalla about 10 years
    Thank you for your reply, Yes it worked now but not for mail.mydomain.com, I tested it on another sub-domain and I got this domain blocked. The funny part here is that I can't get this sub-domain works again! lol :D Even after removing your provided code from the .htaccess, So I have mail.mydomain.com still loading the default website page and the subdomain that holds my clients' area is blocked! .. can you help me get the subdomain back to work again? Thank you very much in anyway :)
  • Mina Hafzalla
    Mina Hafzalla about 10 years
    Never mind, I figured it out and the sub-domain worked again, but still have mail.mydomain.com redirecting to default page, if you have any suggestion please tell me. Many thanks :)
  • Arjan
    Arjan about 10 years
    @MinaIsaac, why did you accept this as the solution if it didn't work? Now future visitors will think it did work for you, so should also work for them. And what exactly did you use for your last test, and what was wrong that made the other domain be blocked? Again, things like "it does not work" and "I figured it out" are not helpful. And it seems to me that the text in your question is outdated.
  • Alex
    Alex about 10 years
    @MinaIsaac, indeed, don't just accept an answer to close the issue and forget. If no answer fits your solution, then don't accept any. Listen to Arjan, tell us what's up. You've asked a question, now follow through so that the community could also gain from it.