mod_rewrite to redirect subdomain

Discussion in 'Apache' started by Cryptix, Sep 3, 2005.

  1. #1
    Hi,

    I've been reading alot about re-directing subdomains to directories, and have tryed various examples on my webserver, unfortunately nothing works.

    Basically what I'm trying to do is redirect something like:

    http://subdomain.website.com/page.html

    to

    http://www.website.com/~subdomain/page.html

    I want to ensure that the page the user is currently visiting is maintained, so that they can type that in using the subdomain initial subdomain method.

    Unfortunately, I do not have access to a shell account through my host, so I need to create a mod_rewrite rule to do this.

    Any help is appreciated,

    Thanks.
     
    Cryptix, Sep 3, 2005 IP
  2. I. Brian

    I. Brian Business consultant

    Messages:
    810
    Likes Received:
    59
    Best Answers:
    1
    Trophy Points:
    145
    #2
    Hm...not answered. I've tried a couple of combinations with .htaccess but not been able to get it to work so far.

    EDIT: Okay, got it now, I *think* - into your .htaccess at your root:

     
    I. Brian, Dec 29, 2005 IP
  3. atapi

    atapi Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi

    Here is what I want to do.
    I want to have any subdomain that is called be rerouted to my
    /home/site.com/httpdocs/index.php

    I want the urls
    http://something.domain.com
    to be routed to the same folder as
    http://domain.com

    But I want subdomains to be created on the fly.
    so I cant symbolically make folders for all of them
    ln /home/site.com/something(source) /home/site.com/httpdocs(target)
    because i want subdomains to be automatically created.

    in my index.php file I just want to detect the subdomain and use it as a var

    How do I get dns to route any dynamic subdomain to the proper ip
    and how do i get mod rewrite to foward any requests for a domain to one folder

    Thanks
    Atapi
     
    atapi, Mar 20, 2006 IP
  4. sunboy2

    sunboy2 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi.

    Here's what you gave:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain.website.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.subdomain.website.com$
    RewriteRule ^(.*)$ http://www.webside.com/subdomain/ [R=301,L]

    And this works, except that the redirection is visible. What if I want to have hidden redirection?

    I don't know if this made any difference, but I removed the ~ from ~subdomain, and you had "http://http://" in the url on the 4th line.

    Thanks,

    N

     
    sunboy2, Aug 23, 2006 IP