remapping dynamic subdomain 
May 27th, 2009, 09:58 AM
|  | Expert | | Join Date: Sep 2006
Posts: 189
| | |
Hi, I'm working on a web app and want to be able to offer my users a URL such as:
username.mydomain.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
| 
May 30th, 2009, 06:36 PM
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9 | | | re: remapping dynamic subdomain
I'm afraid you'll likely need access to the server's setup. No idea how you'd go about it, though.
| 
May 30th, 2009, 06:45 PM
|  | Expert | | Join Date: Sep 2006
Posts: 189
| | | re: remapping dynamic subdomain
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
| 
May 30th, 2009, 07:20 PM
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9 | | | re: remapping dynamic subdomain
You can use the RewriteCond stuff for that. Something like this (untested): -
RewriteCond %{HTTP_HOST} !^sub1.site.com
-
I will do some testing to find the correct syntax.
| 
May 30th, 2009, 07:23 PM
|  | Expert | | Join Date: Sep 2006
Posts: 189
| | | re: remapping dynamic subdomain
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
| 
May 30th, 2009, 07:51 PM
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9 | | | re: remapping dynamic subdomain
I think my above syntax is correct. For multiple sites, you could do this: -
RewriteCond %{HTTP_HOST} !^sub1.site.com
-
RewriteCond %{HTTP_HOST} !^sub2.site.com
-
RewriteCond %{HTTP_HOST} !^sub3.site.com
-
# etc..
-
# And then your rewrite rule.
-
| 
June 21st, 2009, 10:42 AM
|  | Familiar Sight | | Join Date: Mar 2008 Location: Southern California
Posts: 221
| | | re: remapping dynamic subdomain
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 - #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.thedomain.com
displays http://www.thedomain.com/profile/?first=ann-marie&last=jones
as long as a wildcard subdomain is set up, this code should be good to go
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|