If your sites are simple in how they use EE templates, you can use a CNAME to map your subdomains to your main domain, and then use some simple redirect rules to route requests to the correct EE templates.
So, say your main site is: www.example.com and you map two subdomains, sub1.example.com and sub2.example.com as CNAMEs. Then, in EE, say you have corresponding template groups:
- site (the default, for the www.example.com site)
- sub1 (for your sub1.example.com site)
- sub2 (for your sub2.example.com site)
Then, in your .htaccess, you could use these kinds of redirects:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub1\.example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/index\.php/sub1/.*$ [NC]
RewriteRule ^(.*)$ /index.php?/sub1/$1 [L]
RewriteCond %{HTTP_HOST} ^sub2\.example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/index\.php/sub2/.*$ [NC]
RewriteRule ^(.*)$ /index.php?/sub2/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
(note that those redirects assume your Apache is using FCGI. If it's using mod_php, you don't need the ? in the RewriteRules -- e.g.,
RewriteRule ^(.*)$ /index.php/$1 [L]
)
So, with the above, a request to www.example.com would map to the default EE template, site/index. A request to sub1.example.com would map to the sub1/index. And a request to sub2.example.com would map to sub2/index.
The more complicated the sites, generally, the more complicated the structure of your EE templates. And, I don't think this approach scales very well, e.g., not having distinct 404 errors for different sites and other possible complications with URLs for the subdomains.
But, if the subdomain sites are, say, just 1-page landing pages, I think this approach works well enough.