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!
handling subdomain redirects?
Moderator: General Moderators
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.
Is this the most logical way, or is there something better?
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;
}-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Might wanna look at: http://ca3.php.net/manual/en/function.parse-url.php
setting up mod_rewrite redirects
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.P.S., I would prefer to keep the subdomain in the URL throughout navigation.
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.