1

I have the domain example.com and the test.example.com running on apache server. For some reason when I try to visit test.example it is redirected to www.test.example and by consequence a Server not found error is displayed in the browser. Both .htaccess (root and subdomain folder) files are empty.

Additional facts

I have another subdomain xyz.example.com pointed to public_html/xyz directory with some content inside (index.html with "hello world message") and it works fine if I use xyz.example.com instead of www.xyz.example.com. So, can you help me to point to the right direction in order. I have a vps and I am able to change any file if is required.

Below you can find my virtual host configuration.

<VirtualHost xx.xxx.xxx:80>
    ServerName test.example.com
    ServerAlias www.test.example.com
    DocumentRoot /home/example/public_html/test
    ServerAdmin [email protected]
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/test.example.com combined
    CustomLog /usr/local/apache/domlogs/test.example.com-bytes_log "%{%s}t %I  .\n%{%s}t %O ."

    ScriptAlias /cgi-bin/ /home/example/public_html/test/cgi-bin/

    # To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/std/2/example/test.example.com/*.conf"

</VirtualHost>
3
  • 2
    Why are you using ServerAlias www.test.example.com if you don't need it?
    – j0k
    Commented Sep 6, 2012 at 5:22
  • Because when I saw the othres virtual servers (auto-generated by cpanel) I thought that this property was required
    – manix
    Commented Sep 6, 2012 at 5:25
  • Looks like a similar problem to: webmasters.stackexchange.com/questions/34165/…
    – MrWhite
    Commented Sep 6, 2012 at 8:23

1 Answer 1

1

The issue here will be the ServerAlias directive. Duplicating vhost files from other sites can be an issue as you don't need to have all those directives. The bare bones vhost file you need is...

<VirtualHost xx.xxx.xxx:80>
    ServerName test.example.com
    DocumentRoot /home/example/public_html/test
</VirtualHost>

Everything else in the vhost is additional directives to add if you need them, such as custom log locations, alias records, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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