Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

how to create a virtual subdomain system?

Options
  • 29-04-2006 4:00pm
    #1
    Registered Users Posts: 3,514 ✭✭✭


    a project i'm going to undertake in the summer will require a user system which generates a virtual subdomain for users who register with my site.

    For example the user john signs up and is given a subdomain to access his account, john.website.com, which when rendered in the browser will automatically bring up http://website.com/profile.php?username=john or similar.

    How can this be acheived? I know can it can be done with .htaccess but won't that require configuration from myself each time a new user signs up? I would like this system to be automated as much as possible. I will be developing in PHP so if anyone knows of a way to do this....

    Cheers


Comments

  • Registered Users Posts: 7,739 ✭✭✭mneylon


    You'll also need to wildcard the DNS

    Have a look at Wordpress MU. There's support for on the fly sub-domains in that, though I can't remember off the top of my head what you have to do to make it happen


  • Registered Users Posts: 2,157 ✭✭✭Serbian


    I know can it can be done with .htaccess but won't that require configuration from myself each time a new user signs up?

    You can do this with a combination of Wildcard DNS as Michele points out and mod_rewrite. The rewrite rule would look something like this:
    RewriteCond  Host:  (?:www\.)?site1\.com
    RewriteRule  (.*)   /profile.php?username=$1
    
    You wouldn't need to add to this rule each time someone adds a profile, it's completely automated.


  • Registered Users Posts: 3,514 ✭✭✭Rollo Tamasi


    very good. I will look more into Wildcard DNS and mod_rewrite. Cheers lads.


    Found this code on the net which should do the trick.
    RewriteEngine On
    
    # Extract the subdomain part of domain.com
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.website\.com$ [NC]
    
    # Check that the subdomain part is not www and ftp and mail
    RewriteCond %1 !^(www|ftp|mail)$ [NC]
    
    # Redirect all requests to a php script passing as argument the subdomain
    RewriteRule ^.*$ http://www.website.com/profile.php?username=%1 [R,L]
    


  • Registered Users Posts: 92 ✭✭cianuro




Advertisement