www.webdeveloper.com
Results 1 to 7 of 7

Thread: Sub domains

  1. #1
    Join Date
    Jul 2005
    Posts
    7

    Sub domains

    Hi! I am preparing a game website and each game will have it's own page. I want the URL to be in the format http://gamename.domain.com/. Can anyone supply me with the code I need to do this please.

  2. #2
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    It doesn't take code to create a sub domain. You need to first log into your server as the admin and then add a subdomain. (there should be a button somewhere)
    Then each subdomain will have it's own folder. call a file index.htm or index.html and it will be used as the index of that subdomain.

  3. #3
    Join Date
    Jul 2003
    Location
    New York City
    Posts
    2,771
    The changes need to be applied in your Nameservers. Addmittedly, if you have a control panel for your website like CPanel, it's generally as easy as simply clicking "Add Subdomain", but it will vary depending on your host and configuration.

  4. #4
    Join Date
    Jul 2005
    Posts
    7
    I talked to the hosting company and they said I just need a bit of PHP code in my root folder.
    Last edited by Nine Years Old; 08-08-2005 at 05:25 PM.

  5. #5
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    You are correct. All you need is a little PHP code. What your host has set up is called psuedo sub domains as it simulates real sub domaining but no DNS or virtual server alterations are needed. Your host has set up a wildcard DNS entry (*.domain.com) and virtual server which point all sub domains into your root directory. Here's how to use it. Make a directory in your root folder called games and put all your games web pages in there. Name each one as follows: 'gamename.php'. Now put the following code right at the top of your 'index.php' file in your root directory and everything will work as you hoped.
    PHP Code:
    <?php

    $host 
    $_SERVER['HTTP_HOST'];
    $domain 'domain.com';            //alter to suit
    $games_directory '/games/';    //alter to suit
    if(($host != $domain or $host != 'www'.$domain) and list($game) = spliti('\.'$host) and file_exists($games_directory.$game)){ 
        include(
    $games_directory.$game.'.php');
        exit();
    }else{
    // display default root directory contents (index.php) as this is the domain root file
    }

    ?>

  6. #6
    Join Date
    May 2005
    Posts
    93
    Either that, or you could use an .htaccess file and ModRewrite.

  7. #7
    Join Date
    Jul 2005
    Posts
    7
    I've gone with Bokeh's PHP code. I've uploaded it to the server and it seems to be working fine without the changes the other posters said I would need to make. Thanks mate!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles