2

I am having an issue with my virtual host setup for days. My server is a vserver with debain linux and I am trying to add two new domains which will be redirected to their own subfolders.

Domain1.com --> /var/www/domain1

Domain2.com --> /var/www/domain2

The setup is working fine, but the domains are not redirecting to the subfolders but the server root directory. So if I open "domain1.com" I get redirected to "domain1.com/mail" which is the roundcube installation.

Here is how I did the setup:

/etc/apache2/sites-available/domain1

<VirtualHost domain1.com>
   ServerAdmin webmaster@localhost
   ServerAlias domain1.com *.domain1.com
   DocumentRoot /var/www/domain1
</VirtualHost>

/etc/hosts

127.0.0.1 localhost.localdomain localhost domain1.com www.domain1.com

I just don't get it why it's not redirected to the subfolder... Can someone please tell me what I am doing wrong?

  • It's working as designed...DocumentRoot tells Apache what to serve. If you want it to go to another folder, use a redirect. – Nathan C Dec 23 '13 at 20:08
  • Well yeah the DocumentRoot is the subfolder /domain1 and the index.html which is inside should be displayed if the domain get's called. But if you open the domain you will be redirected to the server's root directory... How would a redirect look like? – Fex del Sollo Dec 23 '13 at 20:11
1

I suspect its because you dont have ServerName directives in your virtualhost stanzas. The domain1.com in <VirtualHost domain1.com> simply tells apache to listen on the address that domain1.com resolves to.

Example VirtualHost Stanza

<VirtualHost domain1.com>
   ServerName domain1.com
   ServerAdmin webmaster@localhost
   ServerAlias domain1.com *.domain1.com
   DocumentRoot /var/www/domain1
</VirtualHost>
|improve this answer|||||
  • thanks for your answer, sadly this doesn't change anything :( – Fex del Sollo Dec 24 '13 at 11:12
  • Then I suspect you have a stanza somewhere else in your configuration that conflicts with your domain1 and domain2 stanzas. You could perform something like: grep -R VirtualHost /etc/apache2/* to find other virtualhost stanzas in your configuration. If they are not needed, remove them – GeoSword Dec 24 '13 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.