I have this configuration of virtualhost on my server. Everything works correctly except subdomain with www. When I go to URL with www I get the 404 error. I tried to solve this problem with mod rewrite but I did not know how to do it. Could someone help me? Thanks.

<VirtualHost *:80>
    ServerAdmin mail@localhost
    ServerName domain.com
    ServerAlias www.domain.com
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/domain.com/www/
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin mail@localhost
    ServerName *.domain.com
    ServerAlias *.domain.com
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/domain.com/sub/%-3+
</VirtualHost>
link|improve this question
feedback

migrated from stackoverflow.com Mar 3 '11 at 19:43

This question came from our site for professional and enthusiast programmers.

2 Answers

Try using DocumentRoot instead of VirtualDocumentRoot for www.domain.com?

link|improve this answer
I tried DocumentRoot but it still not working. – user73062 Mar 4 '11 at 8:07
feedback

I don't think you can use wildcards on ServerName (as opposed to ServerAlias), perhaps that's causing problems somehow? Try ServerName domain.com on the wildcard virtual host.

Also, you should probably post the 404's in your error_log. The actual path reported missing may come handy to know how apache is resolving the request.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown