Page 1 of 1
handling subdomain redirects?
Posted: Mon Feb 05, 2007 1:40 am
by jrucifer
I have a wildcard subdomain pointing to my site. My question is, can I run a PHP script to pull the subdomian from the URL?
So if the URL is
http://username.domain.com, pull "username" and set it equal to a variable?
Is this possible, or do I have to go crazy setting up mod_rewrite redirects?
P.S., I would prefer to keep the subdomain in the URL throughout navigation.
Thanks in advance for any help!
Posted: Mon Feb 05, 2007 2:06 am
by jrucifer
Okay, I decided to stop being lazy and try to figure it out on my own a little more...
what I came up with is pretty... shotty, but it works.
Code: Select all
$host = $HTTP_HOST;
$names = explode(".", $host);
foreach($names as $name) {
if($name == "www" or $name == "domain" or $name == "com") {
continue;
}
else {
$name = $name;
}
Is this the most logical way, or is there something better?
Posted: Mon Feb 05, 2007 2:10 am
by alex.barylski
Posted: Mon Feb 05, 2007 7:53 am
by m3mn0n
setting up mod_rewrite redirects
P.S., I would prefer to keep the subdomain in the URL throughout navigation.
Well, with certain uses of mod_rewrite you're not doing any redirecting per se. And by setting it up, you can keep the sub domain in the URL, plus send a customized variable of whatever it is in the sub domain part.
No extra code would be needed for URL parsing.
At first it may be daunting, but it's really not so bad once you get into it. We have
a forum setup with examples and such regarding mod_rewrite. So if you chose to use that, be sure to post there if you get answers and I'm sure you'll get answered in no time.
