When people type a website’s address, they often leave out the www. For SEO and server reasons, it makes sense to redirect them to the www version of the site.
A www domain helps SEO goals by reducing the chance for split page ranking or duplicate content when indexed by a search engine. Plus, visitors can have difficulty accessing a non-www domain, which would negatively influence its SEO.
To reap the advantages of a www domain, you can redirect a non-www domain to www. There are a few ways to go about this – we'll cover those here. As with any project like this, make sure to have a backup of your website files before attempting any of the following methods, just in case an error takes place.
Redirecting a non-www domain to www. using hPanel
Placing a rule in the .htaccess file is the easiest way to redirect a non-www URL.
If you use hPanel, access the .htaccess file by going to Files, then File Manager. Then go to public_html, right click on .htaccess, and click Edit.
Find the following line : RewriteEngine On
Copy and paste the following, and add it after the above line. Be sure to edit startup.com to your domain name:
RewriteCond %{HTTP_HOST} ^startup.com [NC]
RewriteRule ^(.*)$ http://www.startup.com/$1 [L,R=301]
Save the changes and you’re done.
Redirecting a non-www domain to www. using cPanel
If you’re using cPanel, redirect users by going to Redirects in your Domains Settings, then navigate to Type and select Permanent (301).
Next, go to https?:// and enter the page you are redirecting, leaving the path section empty. Type the website’s www URL where it says Redirects to. Select Do Not Redirect www and uncheck Wild Card Redirect. Press Add.
Redirecting a non-www domain to www. using Cloudflare
Using a Content Delivery Network like Cloudflare to help with site performance comes with the benefit of being able to use it to perform redirects like this one.
To do so, go to your Cloudflare dashboard and click on Rules. Press Create Page Rule and then enter the non-www URL you are trying to redirect. Set the page rule to Forwarding URL and the status code to 301 – Permanent Redirect.
Finally, type in the URL with the www and click Save and Deploy.
Redirecting a non-www domain to www. using NGINX
1) Log into VPS account using an SSH like PuTTY.
2) Navigate to /etc/nginx/
3) Type in the following command to view the directory:
[server]$ sudo ls – la
4) Enter your password
5) Type in the following command to edit the nginx.conf file:
[server]$ sudo nano nginx.conf
6) Add the following lines of code. Make sure to change the startup.com pieces of code to your domain:
server {
server_name yourdomain.com;
return 301 $scheme://www.yourdomain.com$request_uri;
}
7) Restart the NGINX server with the following command:
sudo systemctl restart Nginx
Redirecting a non-www domain to www. using Apache
If you use Apache, navigate to edit the .htaccess. You will use the SSH terminal to complete the redirect:
1) Enable mod_rewrite with this command:
$ sudo a2enmod rewrite
Restart the Apache server with this command:
$ sudo systemctl restart apache2
2) Enable .htaccess with this command:
$ sudo vi /etc/apache2/sites-available/000-default.conf
Add this code before the
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
3) Restart Apache
4) Create the .htaccess file with this command:
$ sudo vi /var/www/html/.htaccess
Add the following lines to the file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Restart the Apache server
Want to make www redirects even easier? Try Entri.
Most non-technical end users struggle with setting up www redirects on their own, and many don't even know they need to.
Entri makes it easy for end users to set up www redirects, and even configure their DNS records at the click of a button.
Connect more domains, and retain more users with a product experience they're going to love.