• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

creating sub domains... or custom user directories

Hey all,

I have a system where users register and create a blog. I want the system to create a custom domain such as myname.blogsite.com

or

blogsite.com/myname

I don't want a million directories however in the system... any thoughts as to how I could do this.

0
phenixfilms
Asked:
phenixfilms
  • 2
2 Solutions
 
dr_dedoCommented:
you can use mod_rewrite in apache in a way that blogsite.com/myname redirects to blogsite.com?abc=sdfdfsdfdsfdf

also, you can create that manually, add error handler to 404(file not found) error via apache, say a file named redirect.php, this file can handle the redirection itself, e.g., it checks the desired url and correlate it with the appropriate one from the db and redirects the user to it, if no match is found, and error page saying page can't be found is published :)
0
 
pixayaCommented:
Hi,

I did something simular on one of my sites. The following code gets the requested URL, example myname.blogsite.com, and then gets the 'myname' part from the URL.

Once you have the 'myname' part you can forward the user to which ever page you want.

//get the url
$host = $_SERVER['HTTP_HOST'];
//check that the main site wasn't requested
if(strtolower(substr($host, 0, 3))!=='www'){
      //get the sub domain
      $findDot = strpos($host, '.');
      //if found
      if($findDot>0){
            //lower case
            $subdomain = strtolower(substr($host, 0, $findDot));
            if($subdomain == "mydomain"){
                  header('Location: apage.html');
            }
      }
}

It worked for me, so hopefully your hosting setup will work with it too.

Craig.
0
 
pixayaCommented:
Hi,

I forgot to mention this code should go on your index page...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now