Question

Cname Wildcard Redirects to main domain only

I noticed recently some strange behaviour - I tried to configure CNAME wildcards for all the sites on my droplet, so that www.example.com, wwww.example.com, etc., all lead to example.com. This worked fine with the first/main site I made on my droplet, let’s call that main.com. So typo.main.com goes to main.com. The funny thing is, while I tried to set up the same pattern for the other sites on my droplet, typos such as wwww.othersite.com still take me to main.com. Bit of a n00b here, probably missing something obvious…

CNAME * mainsite.com. (works) CNAME * othersites.com (don’t work)

Subscribe
Share

Are both sites on same droplet ? If yes you could made some mistakes in Virtual Host (Server Block) config. What web-server you use ? There is possibility that you configured Virtual Host to redirect all domains to one html root

Yep they’re on the same droplet. I wonder if the issue has something to do with the “default server” setting? Using Nginx/Ubuntu:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/sammypotato.com/html;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name sammypotato.com www.sammypotato.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}
        location /daryladmin {
                auth_basic "Admin Login";
                auth_basic_user_file /etc/nginx/pma_pass;
        }
        error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

server {
        listen 80;
        listen [::]:80;

        root /var/www/chezteva/html;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name chezteva.com www.chezteva.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}
        location /daryladmin {
                auth_basic "Admin Login";
                auth_basic_user_file /etc/nginx/pma_pass;
        }
        error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Not completely sure if this is the source of the issue or just a typo in your question.

CNAME * mainsite.com. (works)
CNAME * othersites.com (don't work)

As they are written here the second record would not function since it is missing the . at the end. Without this, the DNS system will consider this to be just part of the domain name.

I assume that these CNAME records are on separate domains since having multiple wildcards on one domain would not work properly since only the first one encountered would ever be used. If you can share your actual domain name or paste your zone files in their entirety it would make it much easier to assist you in getting this working as you want it.