Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On single machine I've setuped two WordPress sites using aproperiate setus like below for each in apache sites I have separate configuration for each domain:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www_domain1

        <Directory /var/www_domain1/>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ServerName domain1.com
        ServerAlias www.domain1.com

        ErrorLog /var/log/apache2/error_domain1.log
        CustomLog /var/log/apache2/access_domain1.log combined
</VirtualHost>

and .htaccess in a destination folder

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
order deny,allow

<Files wp-config.php>
  order allow,deny
  deny from all
</Files>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

and I have two probles:

  • www.domain1.com is always redirected to domain1.com
  • foo.domain2.com is redirected to domain1.com (domain1 is alphabetically first, I think, but still this not what I want)
share|improve this question

2 Answers 2

Redirection is not caused by setting the servername and alias but very much more like "UseCanonicalName On" .. it should be set to off.

And second issue, you should add "NameVirtualHost *" to the main configuration file (depends on platform/distro you are running). Put the * in there, not the ip address since you have * in your virtual host definitions too.

share|improve this answer

The "redirection" is caused by setting the servername to "domain1.com" with an alias of "www.domain1.com". This causes Apache to treat all references to "www.domain1.com" as if they referred to "domain1.com". If you don't want this behavior, don't create the alias.

It sounds like you may be missing a "NameVirtualHost xxx.xxx.xxx.xxx" directive in your main httpd.conf file to tell Apache to use name-based virtual hosts - which would explain why requests for both virtual hosts are directed to the first virtual host configured.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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