Results 1 to 1 of 1

Thread: Multiple Sub-domain Site Script

Threaded View

  1. #1

    Multiple Sub-domain Site Script

    Hi folks, my first post here

    I am developing a PHP script that customizes a web page template according to the sub-domain that was used to access the site. Each sub-domain will be owned by a member of the main host site so their details are used to customize the page.

    So my plan is to use .htaccess on LAMP (Linux, Apache etc.) hosting to rewrite the URLs from: to
    Then index.php will produce the custom page.

    My understanding is that the DNS Zone File for the website needs to have an entry to handle wildcard subdomains.

    So I can use WHM (Web Host Manager) to add an entry like:

    * IN A

    where the IP and domain name is as per my site.

    Or I ask my Tech support at my host to do this for me.

    So if this works, any sub-domain at my site should display the home page.

    Now, to pass the sub-domain value to the index.php script, I will use .htaccess

    I think the code I need is something like:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^[-a-z0-9]{2,}\..+$ [NC]
    RewriteRule ^/(.*)$ /index.php/?sub=%1 [R=301,L]
    This then, allows the sub-domain value to be accessed by the PHP script.

    Well I will be trying to get this working on Monday but thought it would be good to post it up here.

    Note that I have not tested this out yet, it's just what I think may work.

    It turned out to be quite simple:

    In cPanel simply add a new subdomain using the wildcard character *

    And here is a test script to use in index.php that displays the name of the subdomain:
    $host = getenv('HTTP_HOST');
    $pattern = '/([-a-zA-Z0-9]{2,})\.[^c]/';
    preg_match($pattern, $host, $matches);
    $subdomain = $matches['1'];
    echo"Subdomain: $subdomain";
    Last edited by Andy101; 24 August, 2009 at 03:35 AM.

Similar Threads

  1. Replies: 0
    Last Post: 29 September, 2010, 08:34 AM
  2. Domain for a Script Site
    By shivachettri in forum Domaining
    Replies: 6
    Last Post: 1 April, 2010, 16:08 PM
  3. [WTS] Coupons Site, Great Keyword Domain, Awesome Script
    By ChaoscripT in forum Sites
    Replies: 6
    Last Post: 17 March, 2010, 20:43 PM
  4. Replies: 9
    Last Post: 15 May, 2009, 19:59 PM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts