lameei
By:
lameei

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

October 7, 2014 3.5k views

My DNS settings are as follows:

$TTL    1800
@       IN  SOA NS1.DIGITALOCEAN.COM.   hostmaster.[mydomain.com]. (
            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.zohomail.com.
            MX 20   mx2.zohomail.com.
@   IN A    [SERVER-IP-ADDRESS-REMOVED]
www CNAME   @

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

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 mydomain.com and a server root of /var/www/mydomain.com/public_html/. Apparently /var/www/ is the server root for the default domain, which you are seeing because you don't have a configuration for www.mydomain.com. You should be able to just add www.mydomain.com as a server name for the mydomain.com configuration.

  • Here is the config file for myDomain.com:

    <VirtualHost *:8000>
        ServerAdmin info@myDomain.com
        ServerName www.myDomain.com
        ServerAlias myDomain.com
        DocumentRoot /var/www/myDomain.com/public_html
        <Directory />
            Options FollowSymLinks
            AllowOverride All
        </Directory>
        <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
    
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
        </Directory>
    
        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
    </VirtualHost>
    
    

    myDomain.com refers to the default settings but www.myDomain.com 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 mydomain.com:8000 in your browser?

  • I have installed and configured Varnish on my VPS. mydomain.com:8000 loads nothing. There was an entry inside /etc/hosts for mydomain.com with IP of 127.0.0.1 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 www.mydomain.com. It should be altered to also match my domain.com or add another one to match that.

    It's likely that mydomain.com:8000 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.