first you need to set your main domain to act as a catch-all subdomain. its like putting ServerAlias * so that each subdomain which is requested to the main domain reaches the same place. I mean if your main domain root is /home/admin/abc.com/htdocs/ then your catch-all setup shall send all sub-domain requests to that same directory /home/admin/abc.com/htdocs/ and then in the index.php file of this directory you can do this <? global $domainname; global $subdomainname; $domainarray = explode('.', $_SERVER['HTTP_HOST']); $index=count($domainarray)-1; $domainname= $domainarray[$index-1].".".$domainarray[$index]; $subdomainname=""; for($i=0;$i<$index-1;$i++) { if($subdomainname=="") { $subdomainname=$domainarray[$i]; } else { $subdomainname=$subdomainname.".".$domainarray[$i]; } } ShowCustomizedPageForsubdomain($subdomainname); ?> PHP: This function ShowCustomizedPageForsubdomain($subdomainname) can be easily implemented in two ways: 1) Either your store Page's Html in your database and all this function would do is to pick up that html code for the provided sub-domain from the database and simply "echo" or "print" it. 2) or you can simply have standard actual pages for each subdomain and you simply include them here like this ob_start(); include "http://url_of_the_page_you_want_to_show"; $data=ob_get_contents(); ob_clean(); PHP: this Object buffer will return you that page's content in the variable "$data"; you simply echo $data; PHP: hmm , going more deep, Second Implementation of your function is like this function ShowCustomizedPageForsubdomain($subdomainname) { ob_start(); include "http://url_of_the_page_you_want_to_show_for_this_subdomain"; $data=ob_get_contents(); ob_clean(); echo $data; } PHP:
i think you have to won a server , at least VPS to do that because you are not allowed to do this thing on shared hosting really if you don't have a server , then just use a folder
I faced the same problem some time ago and VPs wont able to do that. I'm not sure if VPS had changed but at that time I was required to have full dedicated server with root access. Ask your provide to run the script for you. Thanks
What you're looking for is called wild-card subdomains and you can get the low down on getting it set up here ( hxxp://www.google.com/search?q=wildcard+subdomains+tutorial ) ... several good tutorials there. I've heard that hostgator will set them up on some of the shared boxes but you have to get the right tech support guy. If you try and he says no, wait a week and try again. Any vps or dedicated will allow you to do this. It's all handled through command line and only takes an hour or so to set up. DNS has to resolve just like normal domain propagation though.
I couldn't get this done on hostgator hosting... maybe i have to get the right tech support guy. I'll try again in a few days.
It's not about VPS vs dedicated server, it's about whether or not you have access to make the required changes. The only pieces of the puzzle that require admin access are the change to httpd.conf and some DNS setup.
Why not just have a .htaccess forward a subdomain request to directory, such as sub.domain.com > domain.com/sub. Or even also mask the address to keep the subdomain.