Question

I'm using WHM/cPanel on a CentOS Linux box. When a user types a random sub-domain which does not exist (blahblahblah.mysite.com), they are redirected to defaultwebpage.cgi which has a 200 response header. This is causing SEO issues, is there a way to give a 404 response instead?

Was it helpful?

Solution

WHM does have a place where you can edit the the defaultwebpage.cgi page at Account Functions > Web Template Editor. This allows you to change the appearance of the page but because it's HTML you can't give a 404 header response code.

My solution was to go a step higher and find the file causing the redirect in the first place and have that file produce a 404 response instead of redirecting to defaultwebpage.cgi.

  1. SSH into your server
  2. Browse to your htdocs directory: cd /usr/local/apache/htdocs/
  3. Rename the index file to a PHP file: mv index.html index.php
  4. Edit the index file: sudo nano index.php
  5. Replace the contents with: <?php header("HTTP/1.0 404 Not Found"); ?>
  6. Save the file: Ctrl + O
  7. Close the file: Ctrl + X

Now when a site cannot be found on the server it loads /usr/local/apache/htdocs/index.php which returns a 404 header and no content. You can of course add a custom message inside index.php too if you like but for my purposes a blank page was fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top