0

I have one domain: example.com, and I need to have 2 different sites with this domain like I explain below.

Site 1: example.com

Site 2: example.com/site2

I tried to do a virtual host for each site, I show below:

Site 1 virtual host:

<VirtualHost *:80>

ServerAdmin webmaster@localhost
ServerName example.com
DocumentRoot /var/www/html/site1/

<Directory /var/www/html/site1>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

</Directory>

</VirtualHost>

Site 2:

ServerAdmin webmaster@localhost
ServerName example.com/site2
DocumentRoot /var/www/html/site2/

<Directory /var/www/html/site2>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

</Directory>

</VirtualHost>

However it's not working, when I type example.com it redirects me to example.com/site2 but it's showing page not found, like trying to search the page /site2 under example.com, I need it to be 2 separated websites.

Hope someone can help me. I'm using wordpress and magento for the sites. example.com has Magento 2 and example.com/site2 has wordpress

Thanks!

Oscar Vaz
  • 3
  • 2
  • You've wrong option `ServerName example.com/site2` maybe try with proper one like `site2.example.com` and if you need another project in subfolder check out this https://stackoverflow.com/a/6308164/5274713 – frost-nzcr4 Apr 02 '20 at 17:32
  • Hello, so I practically need to move all installation folder in site 1? – Oscar Vaz Apr 02 '20 at 17:38

1 Answers1

0

A domain name cannot have slashes, information that starts with a slash begins the path section of the URL, which navigates down the website tree.

If you have two sites under the same domain name, the proper way to handle this is through subdomains. In your example that would be:

example.com
site2.example.com

You would need to update your DNS record for the domain, in this example, in the example.com's domain record, there would need to be a new A record for site2.

Then on Apache, what you are doing is fine, you would just need to change site2's ServerName:

ServerName site2.example.com
DocumentRoot /var/www/html/site2/

These two sites do not need to be in the same file structure (they don't even need to be on the same server).

Katie
  • 2,594
  • 3
  • 23
  • 31