How can I show the subdirectory of a server as an index based on domain used to connect to it?

I have 2 domains running in the same directory off the same IP (Via a CNAME record in each's DNS)

the directory shows this in the apache index:

index of /

domainOne.com/
domainTwo.com/

This is shown when you visit the site via it's IP address.

However, I want domainOne.com/html/ to be shown IF the domain is Domain One, and domainTwo.com/html if the domain used to connect is Domain Two.

I tried putting a subdirectory in the CNAME record so it points to 12.34.56.789/domainOne.com/html/ but that obviously didnt work, since CNAMEs can only direct to IPs, not specific folders, which sucks.

Is this possible? If it is, it would make my life SO much easier.

(PS, Im doing everything in my httpd.conf file, I dont have config files per domain, since I couldnt figure out how to connect my domains to AWS... and so now Im so low as to use CNAME records...)

Basically I want to know if I can do this with the rewrite engine if possible.

And honestly, the only reason I want to do this, is so the sites are accessible from the debug address at one location in the same directory, and so that the sites can access resources inbetween eachother.

This is all Ive managed to come up with, and of course, it doesnt work.

RewriteEngine on

<If "%{HTTP_HOST} == 'domainOne.com'">
    Alias "/" "${DocumentRoot}/domainOne.com/html"
</If>

See the site here to understand what I mean at the start (https://mistersircode.com/)

(If the site doesnt have the index in the future, thats likely because I fixed my issue.)


Solution 1:

You need to configure separate virtual hosts for each of your domains in Apache.