What you are search for is a Wildcard Subdomain. You need to register one at your Domain Reseller (*.example.com
), but it is not supported at most hosters, i know. For testing on localhost, you need a custom DNS Server. Take a look at this Answer.
Then it is depended on the Webserver.
For Apache:
<VirtualHost 111.22.33.55>
DocumentRoot /www/subdomain
ServerName www.domain.tld
ServerAlias *.domain.tld
</VirtualHost>
For Nginx:
server {
server_name example.com www.example.com;
root www/pub;
}
server {
server_name ~^(.*)\.example\.com$ ;
root www/pub/$1;
}
For IIS:
<rule name="CustomRule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*.aaa.bbbb.com" />
<action type="Rewrite" url="http://aaa.bbbb.com/{R:0}" />
</rule>