How can I route users using a subdomain configuration in my URL (

I'm updating an app that's using PHP Blitz and converting it to a straight forward PHP / OOP dynamic.

Right now, when the user hits the site, there's a subdomain configuration in place that looks like this:

"erin" is being isolated and identified by this function:

function getSubdomain($url=NULL) {
    if ($url == NULL)
        $url = $_SERVER['HTTP_HOST'];
    $aHost = explode('.',$url);
    $sd = 'www';
    if (count($aHost)>2)
        $sd = $aHost[0];
    return $sd;

It works great, but it would appear that it works only if you've got some kind of configuration in place similar to Larvel or Symfony where the htaccess file has been set up in a specific way to accommodate that configuration.

And I'm speculating, so don't hear me as being overly confident.

Because of the number of users that are utilizing this dynamic where their name prefaces the url of the site, I've got to duplicate this, but I'm not sure how.

Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DamianIT incCommented:
Shouldn't you be doing this via CNAMEs in your DNS ?
Bruce GustPHP DeveloperAuthor Commented:
You may be right.

Since I posted this question, I created a Wildcard in my DNS settings. I was using as my guide. Right now, I'm in "stand by" mode - waiting for my changes to propagate. I don't know if what I did is going to work, though, because even if I successfully redirect my user to a specific URL. I still have to figure out how to grab the first part of the URL in order to have something to query the database.

In other words, if my URL is Seems like my Wildcard would direct that to some page, but I still have to be able to access the "hank" part of the URL and I don't know how I'm going to do that.

DamianIT incCommented:
Well, in terms of world DNS, like or the DNS would have to resolve from the outside, before traffic even hits the htaccess or site code, now there may be other methods of achieving this that I am unaware of, but regardless of that.. this very site (spiceworks) is testament to the fact that it can be achieved.

Essentially, and are both pointing to

So, if you deal with this NS resolution at your hosts CPanel (or what ever kind of back end is running) then you should be able to map folders or redirect in such a way so as to accommodate the traffic that comes in, and from there you could populate those maps or redirected folders with your scripts.

"I don't know if what I did is going to work, though, because even if I successfully redirect my user to a specific URL"
Well, the good thing is your traffic, mostly speaking, won't auto-dial in, they will (presumably) go to  Essentially, DNS is read backwards in the eyes of network the computer actually sees "com brucegust hank", so "hank" should be a folder on your host or subdomain etc .  You really just need to make the provision for 'hank' on your host system.

It's a rather general round about explanation, but depending on what and where you have running, I think this philosophy should get you where you need to be.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Bruce GustPHP DeveloperAuthor Commented:
Damian, I've got another "bead" on this thing and I think it's going to work real well.

I've spoken with the network administrator who did some digging and was able to determine that the dynamics that are processing the subdomains appear to be documented in the apache config file.

There may be more to it than this, but he's going to set me up with a dev server so I can kick the tires and see what's what.

So, never mind the Wildcard scenario and forget the htaccess approach. Here's what I believe will work - check my logic and tell me what you think.

The DNS setting is kind of like the Yellow Pages. When someone types in your URL, the server is processing it as an IP address and connects the user to that particular directory / content.

The Apache config file is kind of like the internal phone directory for a particular site. On the config file that I have, I've got this:


      ServerAlias *
      DocumentRoot ../www/
      SSLEngine On

      Alias /js/              ../www/_common_/js/
      SSLCertificateFile conf/ssl/star_mysite_net.crt
      SSLCertificateKeyFile conf/ssl/star_mysite_net.key
      SSLCertificateChainFile conf/ssl/DigiCertCA.crt

      CustomLog "../logs/apache/access.mysite.log" common
      ErrorLog "../logs/apache/error.mysite.log"


I'm thinking "ServerAlias" is my homerun in that it allows for that kind of scenario when someone types in Without that "ServerAlias," the user would get an error. But because that scenario is addressed in my config file, I've got a dynamic in place that allows for / expects that kind of situation.


Based on what I can see, it would appear that the URL: shuttles the user to the index.php that's sitting on the server and from there, I can use some PHP to grab the characters that precede the "."

Am I on to something, or what?
DamianIT incCommented:
"the dynamics that are processing the subdomains appear to be documented in the apache config file."

Yeah, as long as you deal with, as you say, "Without that "ServerAlias," the user would get an error. But because that scenario is addressed in my config file".. then you can catch all and direct traffic where you want.  I'm not much of an apache programmer, but I have configured a stack of DNS configs for many web developers, and I've seen this executed successfully before... just a little foggy on exactly what they did once we created aliases for it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bruce GustPHP DeveloperAuthor Commented:
That's going to work, Damian!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.