The problem can be resolved by adding one step to the request process. Cloudfront will forward the "Origin Domain Name" as the "Host" header variable in the request. That is the information used by your Web server to decide which virtual host to use when serving content.
Let's assume you want to send your visitor to subdomain1.domain.com and subdomain2.domain.com and both of these are virtual hosts on the same Web server.
First create CNAME entries to your cloudfront distributions. Use one distribution for each subdomain like this:
subdomain1.domain.com. 300 IN CNAME d1234567890.cloudfront.net.
subdomain2.domain.com. 300 IN CNAME d0987654321.cloudfront.net.
Instead of pointing your Cloudfront distributions directly at the load balancer, use an intermediary address in the "Origin Domain Name". So your settings would look something like this for the Cloudfront distributions:
d1234567890.cloudfront.net
Alternate Domain Names(CNAMEs): subdomain1.domain.com
Origin Domain Name: subdomain1-intermediary.domain.com
d0987654321.cloudfront.net
Alternate Domain Names(CNAMEs): subdomain2.domain.com
Origin Domain Name: subdomain2-intermediary.domain.com
Now create additional CNAME entries that direct the intermediary addresses to your load balancer:
subdomain1-intermediary.domain.com. 300 IN CNAME LOADBALANCER.eu-west-1.elb.amazonaws.com.
subdomain2-intermediary.domain.com. 300 IN CNAME LOADBALANCER.eu-west-1.elb.amazonaws.com.
When the request passes through the load balancer and arrives at your server, it will see either subdomain1-intermediary.domain.com or subdomain2-intermediary.domain.com in the "Host" header of the request. All you have to do now is to define your virtual hosts. In IIS the rules would look like this:
<rule name="rule1">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="subdomain1-intermediary.domain.com" />
</conditions>
<serverVariables>
<set name="HTTP_HOST" value="subdomain1.domain.com" />
</serverVariables>
<action type="None" />
</rule>
<rule name="rule2">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="subdomain2-intermediary.domain.com" />
</conditions>
<serverVariables>
<set name="HTTP_HOST" value="subdomain2.domain.com" />
</serverVariables>
<action type="None" />
</rule>