0

I am trying to use the following scenario to create to give registered users there own subdomain to the site. I do not want to add DNS records for every user but if user jon signs up I would like him to see the URL of jon.website.com. It seems that this is possible from other questions that I have read up on.

However my implementation and lack of understanding is holding me up. Here is what I have done so far.

Added DNS wildcard A record for domain

*.website.com --> IP of website ex. 12.2.3.4

Added the following code to .htaccess file in www.website.com/application/

<VirtualHost *:80>
  ServerName server.website.com
  ServerAlias *.website.com
  UseCanonicalName Off
</VirtualHost>

Find subdomain with PHP

preg_match('/([^.]+)\.example\.org/', $_SERVER['SERVER_NAME'], $matches);
if(isset($matches[1])) {
    $subdomain = $matches[1];
}

How I would see this working is, when the user signs up, a directory with the subdomain name is created as in www.website.com/application/subdomainName/ -- I can handle this no prob -- Then on successful login the user is then directed to www.website.com/application/jon/

Am I headed the right direction on this? If yes then how do I get from where I am I where I need to go? This one is quite a bit above my pay grade! Thanks for any advise!

Community
  • 1
  • 1
SuperNinja
  • 1,538
  • 6
  • 22
  • 45

1 Answers1

1

Your starting steps are correct and in the right direction. I don't understand why you are creating the directory though.

You just need to make sure that your site works from any domain. So make sure all URLs and links to resources use an absolute path.

I'm guessing you will want to customize the experience for each user. So, you need to store some meta data against each of your registered users so their sites have a different look and feel. The easiest way to do this is to store the meta data against the subdomain in your database. Simply look at the current subdomain your site is running under and load up the appropriate user to figure out how the site should look.

JohnP
  • 49,507
  • 13
  • 108
  • 140
  • Sorry for the delay on getting back, but been doing research on the answer below and yours as well. As @CD001 said above looks like Virtualhost does not go in the .htaccess file but rather in the http.conf file. The web app resides in www.website.com/application/ so I have to leave there. So what I hope to achieve is when the user creates an account they would have a URL that would read jonDoe.website.com/application/ -- Thanks for the input – SuperNinja Sep 18 '12 at 04:34
  • Yup, the virtualhost needs to be setup with your http conf. And you'd need to setup apache to serve files on multiple subdomains. – JohnP Sep 18 '12 at 05:05
  • so would I have to manually setup Apache for each subdomain or does the question details take care of that for me? – SuperNinja Sep 18 '12 at 14:16
  • As long as your DNS is pointed to the same apache server, I think you should be good. – JohnP Sep 18 '12 at 14:34