Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

how to create a virtual subdomain system?

  • 29-04-2006 03:00PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 7,742 ✭✭✭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, Registered Users 2 Posts: 2,207 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 92 ✭✭cianuro




Advertisement