-   Linux - Networking (
-   -   subdomain redirection problem with virtualhost (

jhwilliams 05-20-2008 06:45 PM

subdomain redirection problem with virtualhost

I have two domain names, domain1.tld, and domain2.tld. In DNS, both have A records pointing to the same ip address, www.domain1.tld and www.domain2.tld are CNAME aliases for their respective domains.

My httpd.conf has the following:

NameVirtualHost *:80
<VirtualHost *:80>
        DocumentRoot /home/domain1/www
        ServerName domain1.tld
        ServerAlias *.domain1.tld domain1.tld

<VirtualHost *:80>
    DocumentRoot /home/domain2/www
    ServerName domain2.tld
    ServerAlias *.domain2.tld domain2.tld
    <Directory /home/domain2/www>
        AllowOverride all
    AccessFileName    .htaccess

when i visit www.domain1.tld, everything is fine. However, when I visit www.domain2.tld, it is redirected to domain2.tld instead of maintaining the 'www' portion. What could be causing this?


jcvlz 05-20-2008 11:46 PM

My first thought is that the ServerName for domain2 is "domain2.tld" and not "www.domain2.tld". In other words, you're *telling* the server that the name of the virtual host does not have a host name. Although, depending on what the rest of your httpd.conf, other configuration files, and servered pages contain - you may also want to look at what other directives are being given to the server (e.g. mod_rewrite). Oh, and take a look at the docs regarding AllowOverride - setting it to "All" could give you some headaches if you're not the only one with write permissions to that documentRoot.

jhwilliams 05-21-2008 05:21 PM

When I change the ServerName of domain2.tld to www.domain2.tld, it just redirects to www.domain1.tld, like the request isn't being "caught" by Apache. I would change the DNS records, but it works fine for domain1.tld, so I don't see what the difference should be?

And yes, each virtual host has it's own user. :-)

I have mod_rewrite on, which changes domain1.tld to www.domain1.tld, and I have the same code for domain2. However, the problem pervades with and without the rewrite from domain2.tld to www.domain2.tld; either way, I keep getting domain2.tld.

Any other thoughts?


All times are GMT -5. The time now is 01:21 PM.