How to route the domain with www and without to one location?

October 7, 2014 2.5k views

My DNS settings are as follows:

$TTL    1800
@       IN  SOA NS1.DIGITALOCEAN.COM.   hostmaster.[]. (
            1412671879 ; last update: 2014-10-07 08:51:19 UTC
            3600 ; refresh
            900 ; retry
            1209600 ; expire
            1800 ; ttl
             IN      NS      NS1.DIGITALOCEAN.COM.
                     NS      NS2.DIGITALOCEAN.COM.
                     NS      NS3.DIGITALOCEAN.COM.
            MX 10
            MX 20
www CNAME   @

The problem is that the domain without www loads index.html in ( /var/www/index.html) and with www loads (/var/www/

How can I fix this issue?

1 comment
2 Answers

It's probably your server configuration. It sounds like you have a configuration for a server with the name and a server root of /var/www/ Apparently /var/www/ is the server root for the default domain, which you are seeing because you don't have a configuration for You should be able to just add as a server name for the configuration.

  • Here is the config file for

    <VirtualHost *:8000>
        DocumentRoot /var/www/
        <Directory />
            Options FollowSymLinks
            AllowOverride All
        <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
        ErrorLog ${APACHE_LOG_DIR}/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
 refers to the default settings but opens the right index.html.

  • I see you are using port 8000 in your VirtualHost directive, which makes me think you are using Apache behind a proxy server. If that is the case, it would also be necessary to alter the configuration of the proxy server.

    Just as a check on this configuration, what happens when you try in your browser?

  • I have installed and configured Varnish on my VPS. loads nothing. There was an entry inside /etc/hosts for with IP of which I removed. Is there somewhere else like this?

  • I have not messed with Varnish before: but, my thinking is it might be a good idea to get your websites working properly first before installing any sort of caching application.

    This way you will have one less "moving part" to deal with as you trouble-shoot.

    Having said that, I have never used Varnish, so I am just talking off the top of my head.

  • The place to look now is at your Varnish configuration. I haven't used Varnish myself. I just spent 5 minutes reading about it to try to find an answer, so this is far from an expert opinion. My guess is that you need to look at the regex that matches It should be altered to also match my or add another one to match that.

    It's likely that gets nothing because port 8000 is closed. I wouldn't go to the trouble of changing anything just to test that.

  • I'm not sure about the DNS record is it correct?

  • It looks good to me.

  • Here is the solution I found : Just deleted the CNAME to WWW and added an A record for it, Bingo it Works right now.

I'm using apache2. And the problem is that the domain with www and without it should open the same index.html which they do not.

Have another answer? Share your knowledge.