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.

htaccess Subdomain Redirect

Discussion in 'Apache' started by theblight, Sep 15, 2006.

  1. #1
    theblight, Sep 15, 2006 IP
  2. brandondrury

    brandondrury Peon

    Messages:
    375
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd like to know this one as well.

    Brandon
     
    brandondrury, Oct 2, 2007 IP
  3. KunkVentures

    KunkVentures Peon

    Messages:
    744
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i don't know about doing this with htaccess, but in PHP its pretty easy.

    Grab subdirectory, append to front of url, redirect to that new url.
     
    KunkVentures, Oct 2, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ([a-z0-9-]+)/? http://$1.domain.com [R=301,NC,L]

    Replace both instances of "domain.com" with your domain name.
     
    krt, Oct 3, 2007 IP
  5. guruwebmaster

    guruwebmaster Active Member

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    guruwebmaster, Mar 10, 2009 IP
  6. huynhtronghoan

    huynhtronghoan Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for your useful link :)
     
    huynhtronghoan, Nov 7, 2009 IP
  7. superstan

    superstan Peon

    Messages:
    244
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    superstan, Mar 9, 2010 IP
  8. monicowebdesign

    monicowebdesign Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This should do it

    Redirect /member.php?id=11&name=john http://john.mydomain.com

    You can also redirect a sub domain to a page on your main site

    RewriteCond %{HTTP_HOST} ^example.yourdomain.co.uk$ [NC]
    RewriteRule (.*) http://www.yourdomain.co.uk/your-page/$1 [R=301,L]

    The $ conditions on the end will redirect something like example.yourdomain.co.uk/this-page to yourdomain.co.uk/your-page/this-page this is very useful if you move a sub domain to your main site. I had do this for a client.
     
    monicowebdesign, Nov 30, 2010 IP