1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to create virtual dymanic subdomain in php with .htaccess

Discussion in 'PHP' started by blognol, Oct 5, 2009.

  1. #1
    I need to create virtual subdomain.
    For example my site is www.xyz.com

    i need to have abc.xyz.com were the abc may be the username ...

    I know we can do this with the help of .htaccess

    Can anyone help ?
     
    blognol, Oct 5, 2009 IP
  2. young coder

    young coder Peon

    Messages:
    302
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try google "dynamic subdomains"
     
    young coder, Oct 5, 2009 IP
  3. BMR777

    BMR777 Well-Known Member

    Messages:
    145
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    140
    #3
    Something like:

    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.yourdomain\.com$ [NC]
    RewriteRule (.*) /redir/$1 [L]
    Code (markup):
    This will redirect any.yourdomain.com to yourdomain/redir/any. You can play with the code a bit if you need to. Also, the \'s in the domain names are required, so don't remove them. :)
     
    BMR777, Oct 5, 2009 IP
  4. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
  5. blognol

    blognol Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    not working, showing file not found error
     
    blognol, Oct 6, 2009 IP
  6. blognol

    blognol Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am ready to pay, if any one give me the correct solution. I need to solutions in php
     
    blognol, Oct 6, 2009 IP
  7. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #7
    #rewrite conditions
    RewriteCond %{HTTP_HOST} !^(YOUR_DOMAIN\.com)$ [NC]
    RewriteRule ^(.*)$ script/index.php?$1

    This rewrite rule directs any subdomain requests to a file named /script/index.php on the local server.

    That script file can use the $_SERVER["QUERY_STRING"] parameter to see what virtual subdomain the request was for and redirect the user correctly, or just provide content for the requested subdomain.

    The rule as written will redirect all requests with a subdomain, even www, to the script file.
     
    goliath, Oct 6, 2009 IP
  8. young coder

    young coder Peon

    Messages:
    302
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    and make a subdomain and name it *

    and add the .htaccess file to it's folder
     
    young coder, Oct 7, 2009 IP
  9. KEEP IT REAL

    KEEP IT REAL Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Try this
    RewriteEngine On
    Options +FollowSymlinks
    RewriteCond %{ENV:REDIRECT_MYFLAG} ^$
    RewriteCond %{HTTP_HOST} ^([A-Za-z0-9]*)\.site\.com$
    RewriteRule ^(.+) %{HTTP_HOST}$1 [E=MYFLAG:1]
    RewriteRule ^([A-Za-z0-9]*)\.site\.com(.*) /([A-Za-z0-9]*)%{REQUEST_URI} [L]
    PHP:
     
    KEEP IT REAL, Oct 8, 2009 IP
  10. bilirkishi

    bilirkishi Well-Known Member

    Messages:
    213
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #10
    not working...
     
    bilirkishi, Dec 8, 2014 IP