How to redirect www to non-www within domains?

What setting to I have to put in DNS at DO for a domain, so that to be redirected to

And what setting to put so that if someone tries to access a non existing subdomain (like to be redirected to Or if not in DNS settings, where?


Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I used an A record and that solved the issue. Thanks!

@sierracircle What Apache version is the advice for? What Linux distro is this for? I tried this and got this error on a CentOS 7 running Server version: Apache/2.4.6 (CentOS) and I got this error:

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

First of all, aren’t we supposed to be editing our Apache Config Files located in /etc/httpd/sites-available? not sites-enabled? Secondly, is our supposed to look like this advice:

<VirtualHost *:80>

    DocumentRoot /var/www/ /public_html
    ErrorLog /var/www/ /error.log
    CustomLog /var/www/ /requests.log combined
    <Directory /var/www/yourwebfolder>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
            Require all granted

This is my question. And lastly, isn’t yourwebfolder supposed to be called a document root? Or are they different? My last question is for Digital Ocean. Can we please get a qualified document that helps CentOS 7 customers make it so the same page with both and have good DNS but we want people who go to both pages only END UP on the domain please? Thanks in advance.

DNS doesn’t do redirection. You have to configure it in your webserver.