Apache default virtual host for multiple domains

2019-09-01 16:46发布

I have, for example site1.com, site2.com, configured with their own virtual hosts in their own files in the apaches enabled and available folders, in their own physical folders on the server and with different .htaccess and they are working fine. Now I want all the other domains that are not separately configured (for example site3.com, site4.com ....) to have one same virtual host, same physical folder, and to execute the same /folder1/folder2/index.php file. So far, I've made some virtual hosts but all I get is "It's working", probably because everything is redirected from the default virtual host to the /var/www. But if I set the DocumentRoot directive in that file, the .htaccess for some reason is not working, and I said that for the defined sites are working OK. What the virtual host file should be called, what should be it's content?

1条回答
唯我独甜
2楼-- · 2019-09-01 17:03

You can define a VirtualHost container that has as many ServerAlias entries as you need.

Here's a very simplified example:

<VirtualHost *>
    ServerName site3.com
    ServerAlias site4.com
    DocumentRoot /var/www/folder1/folder2
</VirtualHost>

If you've already tried creating vhost files, have you restarted apache?

Where to put the vhost files depends on what distro you're using. If you're not familiar with where stuff goes on your distro, check http://wiki.apache.org/httpd/DistrosDefaultLayout.

查看更多
登录 后发表回答