1. Linux

301 Redirect “www” to “non-www” in cPanel

One of the most common support inquires we receive is how to setup a 301 redirect for a domain so that all requests from www are redirected to non-www and vice-versa. There are multiple ways to do it and today we gonna cover it.

cPanel 301 redirect

The easiest way is to use the built-in Redirect option. Login to cPanel and find the corresponding function under Domains tab.

Redirect location in cPanel
Redirects location in cPanel

For example, we want to redirect www.buydomainwithbtc.com to non-www version. Then we select Permanent 301, choose our domain name, and set Redirects to: https://budomainwithbtc.com and click Add.

Setup 301 www to non-www redirection in cPanel
Setup 301 www to non-www redirection in cPanel

On the picture above we highlighted Wild Card Redirect. In case you want all pages of the website to redirect to non-www version of that page and not only home page, you should select this option.

When you have added the redirect, it will appear in the bottom of the page under Current Redirects.

The list of current redirects in cPanel
The list of current redirects in cPanel

Redirect by .htaccess

If you prefer a little bit more complicated solution then you can redirect www to non-www using .htaccess file. It’s located in the public_html folder of your website. Access cPanel File Manager and then navigate to public_html. However there is a tricky thing.

By default .htaccess is hidden and you will need to enable “Show hidden files (dotfiles)” under Settings.

enable hidden files in cPanel
Enable hidden files in cPanel

If you want to redirect www to non-www you can use the code below, replacing the domain name.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^www\.buydomainwithbtc\.com$
RewriteRule ^/?$ "https\:\/\/buydomainwithbtc\.com\/" [R=301,L]

CNAME Redirect www to non-www

No. No. No. Many times our customers write to us, asking how to setup domain redirect using DNS and particularly CNAME. There is no way. DNS are not used for that. Your domain is pointed to a particular IP with the help of DNS. And redirects are performed by the webserver, for example Apache or Nginx.