remapping dynamic subdomain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    remapping dynamic subdomain

    Hi, I'm working on a web app and want to be able to offer my users a URL such as:

    username.mydoma in.com

    but have it map to:

    mydomain.com/controller/method/username

    FYI, I'm using codeigniter PHP framework, which should explain the above URL I need to map to.

    I'm thinking this should be done with mod_rewrite, and I've tried various method to no avail. Any ideas on how to go about this?

    Thanks for any insights!

    Greg
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I'm afraid you'll likely need access to the server's setup. No idea how you'd go about it, though.

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      Hey Markus,

      I have a vps, so I can do what ever. I'm just not sure exactly how to set it up. I added a wildcard domain, so all subdomains resolve, I just need the .htaccess to pick up the slack.

      I actually had something working OK, but it redirected all subdomains. There are some I do not want redirected, like the main application, the demo version, the dev version, etc...all which are on their own subdomain.

      So I need like a list of domains not to remap, and anything else should get kicked to a specific url.

      Thanks for your reply!

      Greg

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You can use the RewriteCond stuff for that. Something like this (untested):

        Code:
        RewriteCond %{HTTP_HOST} !^sub1.site.com
        I will do some testing to find the correct syntax.

        Comment

        • gregerly
          Recognized Expert New Member
          • Sep 2006
          • 192

          #5
          Hey no problem Markus, I appreciate your input. Ok, so it's fairly simple it looks like, I think the hardest part is figuring out how to phrase the google query to find what I'm looking for. I should have guessed it would be ! (not) this domain.

          I'll see what I can work out with this. Thanks again!

          Greg

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            I think my above syntax is correct. For multiple sites, you could do this:

            Code:
            RewriteCond %{HTTP_HOST} !^sub1.site.com
            RewriteCond %{HTTP_HOST} !^sub2.site.com
            RewriteCond %{HTTP_HOST} !^sub3.site.com
            # etc..
            # And then your rewrite rule.

            Comment

            • n8kindt
              New Member
              • Mar 2008
              • 221

              #7
              i just spent all day trying to figure this one out for myself. i started off not even knowing how to use regex to feeling like a guru on this one. i pieced this information from the internet and it has nothing to do with codeigniter but it works for me. like i said i'm still a beginner so any critique of this code is welcome

              Code:
              #quietly redirect subdomain user profile requests
              RewriteCond %{ENV:REDIRECT_STATUS} ^$
              RewriteCond %{REQUEST_URI} !(/.+)$
              RewriteCond %{HTTP_HOST} ^([a-z-]+)\_([a-z-]+)/*\.thedomain\.com$ [NC]
              RewriteRule ^(.*)$ /profile/?first=%1&last=%2 [QSA,L]
              
              #ensure links go to the right place so css, js, etc work
              RewriteCond %{HTTP_HOST} !^([a-z-]+)\_([a-z-]+)/*\.thedomain\.com [NC]
              #also, if not a subdomain add www. for ssl cert (not completely necessary)
              RewriteCond %{HTTP_HOST} !^www\.thedomain\.com [NC]
              RewriteRule ^(.*)$ http://www.thedomain.com/$1 [R=301,L]
              so http://ann-marie_jones.the domain.com
              displays http://www.thedomain.c om/profile/?first=ann-marie&last=jone s

              as long as a wildcard subdomain is set up, this code should be good to go

              Comment

              Working...