Automatically generate subdomains

Discussion in 'Apache' started by halifaxx, Feb 16, 2008.

  1. #1
    Hi all,


    I would like to automatically generate subdomains when a user registers.
    Unfortunately i know very little (jack sh*t) about mod_rewrite and .htaccess etc.

    But my plan is to open .htaccess with PHP when the user subscribes, and add some lines to make http://user.test.com refer to http://www.test.com/users.php?id=1 for example.

    Is this a good idea and if possible, can someone tell me what lines PHP has to write in .htaccess.


    Thx a lot!!
     
    halifaxx, Feb 16, 2008 IP
  2. marksailes

    marksailes Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you have access to the apache httpd.conf have a google for virtual hosts
     
    marksailes, Feb 17, 2008 IP
  3. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #3
    .htaccess code

    
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ! ^www\.test\.com [nc]
    RewriteCond %{HTTP_HOST} (.*)\.test.com [nc]
    RewriteRule /users.php?id=1%
    
    
    Code (markup):
     
    buldozerceto, Feb 17, 2008 IP
  4. halifaxx

    halifaxx Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ill try that!
     
    halifaxx, Feb 24, 2008 IP
  5. halifaxx

    halifaxx Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i've got this code now:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^www.$
    RewriteRule ^(.*)$ http://www.allsites.be/~test/index.html [R=301,L]
    
    RewriteCond %{HTTP_HOST} !^www\.test\.be
    RewriteCond %{HTTP_HOST} ^([^.]+)\.test\.be
    RewriteRule ^/?$ http://www.test.be/index.php?id=%1 [L] 
    Code (markup):
    www.test.be itself refers to www.allsites.be/~test.

    but when i type frank.test.be it doesn't refer to www.test.be/index.php?id=frank

    it just says "Could not found server frank.test.be"

    help! :D (im such a noob at this)
     
    halifaxx, Feb 24, 2008 IP
  6. sweetfunny

    sweetfunny Banned

    Messages:
    5,743
    Likes Received:
    467
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You cant just add a rewrite you need to configure wildcard subdomains on your server like *.test.com so then * can be anything and generated on the fly.
     
    sweetfunny, Feb 26, 2008 IP
  7. halifaxx

    halifaxx Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thx, got it to work now, but i can see the redirect. I'd like to keep the subdomain URL in the adres bar unchanged! (invisible redirect) this is the code i use now:

    Options +FollowSymLinks
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^www.$
    RewriteRule ^(.*)$ http://www.digx.be/~wieper/index.php [R=301,L]
    
    RewriteCond %{HTTP_HOST} !^w{3}\.
    RewriteCond %{HTTP_HOST} ^([^.]+)\.wieper\.be$
    RewriteRule ^(.*)$ http://www.digx.be/~wieper/index.php?p=bedrijvengids&show=detailed&sub=%1 [L]
    Code (markup):
    You can see that there is already a redirect from the site domain i'm using to my main domain.

    When i go to http://visionline.wieper.be i go to http://www.digx.be/~wieper/index.php?p=bedrijvengids&show=detailed&sub=visionline
    which is just like http://www.wieper.be/index.php?p=bedrijvengids&show=detailed&sub=visionline
    But i want to keep http://visionline.wieper.be as URL? Or at least the www.wieper.be domain and not the digx domain.
     
    halifaxx, Feb 27, 2008 IP
  8. halifaxx

    halifaxx Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    nobody? :)
     
    halifaxx, Mar 6, 2008 IP