www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: how to create a virtual subdomain system?

  1. #1
    Join Date
    Dec 2005
    Posts
    123

    how to create a virtual subdomain system?

    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

  2. #2
    Join Date
    Feb 2005
    Location
    BC, Canada
    Posts
    1,098
    You could change conf.httpd to give php access to write .htaccess, and then write it on the fly.
    Corn is no place for a mighty warrior!

  3. #3
    Join Date
    Jan 2005
    Location
    Illinois
    Posts
    815
    I found this at http://www.msfn.org/board/lofiversio...hp/t19527.html
    You'd put it in the .htaccess file:
    Code:
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.website\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.website\.com [NC]
    RewriteRule ^(.*)$ http://www.website.com/profile.php?username=%1 [L,R]
    I'm not sure if that would work for you or not.

    --Steve
    Save The Shirts!
    Don't overuse exclamation marks!!!!!!

  4. #4
    Join Date
    Dec 2005
    Posts
    123
    hi, yes it would seem that .htaccess is the way to go. I found this code which is very similar to what you have posted. You'd need to have wildcard DNS activated as far as i'm aware too by your host.
    Code:
    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]

  5. #5
    Join Date
    Jan 2005
    Location
    Illinois
    Posts
    815
    Yes, that's right about needing wilcard. I wish I could do this on my website but my host doesn't allow wildcards.

    --Steve
    Save The Shirts!
    Don't overuse exclamation marks!!!!!!

  6. #6
    Join Date
    Dec 2005
    Posts
    123
    that's a pity, it's a very nice little feature to have.

  7. #7
    Join Date
    Jan 2005
    Location
    Illinois
    Posts
    815
    I know, you don't have to rub it in!
    I should probably switch hosts. Who are you using? Are they any good?

    --Steve
    Save The Shirts!
    Don't overuse exclamation marks!!!!!!

  8. #8
    Join Date
    Dec 2005
    Posts
    123
    i'm using blacknight.ie , Irish company. I know the bossman a little bit

  9. #9
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Why do you need subdomains. They use more resources and are pointless if the domain and subdomain are located on the same server.

  10. #10
    Join Date
    Dec 2005
    Posts
    123
    for convience. Each user on the site will have an account and instead of getting to it by website.com/profile.php?username=john they can just go john.website.com

  11. #11
    Join Date
    Apr 2006
    Posts
    1

    I could help you with a script

    but it is in Pearl.
    It was on the net 2 years ago and ..it dissapers now
    Fortunately I still have-it.
    It allocates a fixed space every user, registration processs with name/password, possibility for uploading files for users, etc ...
    If it is ok, contact me to send-it to you.
    calin_sb@yahoo.com

  12. #12
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742

  13. #13
    Join Date
    Dec 2005
    Posts
    123
    yes, wildcard subdomains are allowed. Thanks markro, i'll email you.

  14. #14
    Join Date
    May 2008
    Posts
    1
    Quote Originally Posted by Megatron
    hi, yes it would seem that .htaccess is the way to go. I found this code which is very similar to what you have posted. You'd need to have wildcard DNS activated as far as i'm aware too by your host.
    Code:
    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]
    How would I go about redirecting depending on the username (url example: http://www.somewebsite.com/username) would be able to pull its distict variables that would affect the FUI according to the usernames preferences (how those variables would be stored isn't important)... the point is to be able to basically replicate the website when requested at the example url above.

  15. #15
    Join Date
    Jul 2008
    Posts
    1

    Thumbs up

    THANK YOU
    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]

    Edit by admin: no commercial links permitted on the forum, thank you

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