Custom Error Pages for Different Addon Domains

I’d like software or a script that lets me use different custom error pages for different addon domains. In Cpanel at the moment you can only use the same custom error page for all addon domains and the main domain they are under. I don’t even know if what i ask is possible but I thought I’d post it anyway :-)

thorn

Many things are possible when you know what do you want ;-)

Let’s consider various domains you may have at the same hosting in addition to your main domain (site).

A Parked Domain is pointed to the same folder as your main domain and shares the files / pages of your main site.

An Addon Domain is similar to Parked Domains. But it is pointed to a sub-folder of your main domain (site), and can have it’s own settings. However you can’t create error pages for Addon Domains through your Control panel, you can do it by hand.

A Subdomain doesn’t have an independent domain name. It’s a composite domain name which is pointed to a sub-folder of your main domain (site).

Error Pages for Addon Domains

Addon Domains and SubDomains are pointed to sub-folders of your hosting account and can have its own error pages. Create error pages you’d like and upload them to the appropriate folders:
public_html/domain1/error404.html
public_html/domain2/error404.html
public_html/subdomain/error404.html

Now you have to direct error requests to this pages.
The .htaccess files will help you.
If you don’t have the .htaccess files inside this folders, create them with the directive like this below:

ErrorDocument 404 /error404.html

That’s all for Addon Domains.
If your Addon Domains share the same folders use the solution for Parked Domains below.

Error Pages for Parked Domains

Parked Domains are pointed to the same folder as your main domain, so we have to use a script to distinguish requests to various domains.
This solution would use both .htaccess and a PHP-script.

1) At the first step, create various error pages for your domains and upload them into the public_html folder:
public_html/error404-domain1.html
public_html/error404-domain2.html
public_html/error404-main.html

2) At the second step, create a file named as 404.php with the code like this:

<?php
 $domain = strtolower(getenv("HTTP_HOST"));
 if(preg_match("/^(?:www\.)?(.+)$/i",$domain,$matches)) {
  $domain = $matches[1];
 }
 switch ($domain) {
  case "domain1.com":
   include("error404-domain1.html");
   break;
  case "domain2.com":
   include("error404-domain2.html");
   break;
  default:
   include("error404-main.html");
   break;
 }
 exit;
?>

This script would detect the domain and show the appropriate error page.

3) And finally, add the directive like below into the public_html/.htaccess file:

ErrorDocument 404 /404.php

That’s all now.

 

by Michel Komarov, © Copyright 2006. iCoder.com

 

Share in social bookmarking:These icons link to social bookmarking sites where readers can share and discover new web pages.  digg del.icio.us BlinkList Reddit NewsVine YahooMyWeb co.mments

One Response to “Custom Error Pages for Different Addon Domains”

  1. thorn Says:

    Thank you so much for that solution, Michel. That’s exactly what I needed. It works! (of course, you knew that but my hosting account tech support guy said it couldn’t be done!)

    Thanks again :)

Got a question?   Leave a Reply

You must be logged in to post a comment.