SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to do dynamic subdomains using php?

    Hi All,

    In my wesbite, i would like have my site show subdomains, i.e sub1.mydoman.com

    But, in reality, i do only have mydomain.com/sub1

    So, I like to know a way where sub1.mydomain.com should be automatically redirected to mydomain.com/sub1 and the url in the address bar should still be sub1.mydomain.com.

    Any hints?

    Thanks,

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    This is something you have to configure the DNS to do.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I appreciate if anyone can show me any pointer on how it can be done?

    thx

  4. #4
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you have cpanel click on Subdomain

  5. #5
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by caddyfixr
    if you have cpanel click on Subdomain
    I think, s/he was looking for way to do that programatically.

  6. #6
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cant you just do a mod_rewrite?
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  7. #7
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,056
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    mod re-write will do this, i have a rule that'll allow the conversion of *.domain.com to a known folder on the disk... for e.g.

    site1.domain.com is converted to /var/www/domain/subdomain

    is this the sort of thing you want to do?

  8. #8
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, Tim, that's exactly i am lookin to do (using mod_rewrite)

    How can it be done?

    Thanks

  9. #9
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,056
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    I have this contained within the apache conf (httpd.conf) on that server
    Code:
     RewriteCond ${lowercase:%{SERVER_NAME}} ^[a-z-]+\.domain\.com$
     RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
     RewriteRule ^([a-z0-9-]+)\.domain\.com/(.*) /var/www/html/$1/$2
    You'll need to change the 2 instances of domain\.com

    and also the path in the last part to whatever is relevant on your system.

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Dundee, Scotland
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just a note for this to work you will need to have wildcard dns enabled as well as a wildcard entry into your httpd.conf file. If you do not do this the subdomain will not resolve and the server would not know where to direct it anyway.

  11. #11
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,056
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    unless you add each 'valid' dns entry

  12. #12
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Dundee, Scotland
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which would essentially defeat the purpose of what the op intends as far as I understand what he is after.

  13. #13
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any alternate way to tackle this issue? We have multiple sites hosting on the same server and I would like to avoid changing httpd.conf file.

    Can it be handled modifying .htaccess?

    Thanks.

  14. #14
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,056
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    you do tell apache which domain the re-write rules apply to.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •