How to Redirect Non-WWW URLs to WWW in WordPress

In the last article, I’ve shared how you can redirect www URLs to non-www URLs in WordPress. This is pretty important when you want a non-www domain to be your base domain. However, if you want the www subdomain to be your root domain then you need to create proper 301 redirects to your base domain.

So, if you’ve just created a WordPress site or if there are no proper www redirects to your base domain then you should consider redirecting non-www URLs to www URLs.

What Happens in Case of No Proper Redirection?

Here are some issues that you may face when there are no proper redirects to your base domain.

  • Search engines will see your non-www domain and www domain as separate entities.
  • Since the same content (or 404 error in some cases) is shown on both the pages, search engines may see it as the duplicate content.
  • No proper redirection to your base domain may confuse search engines.
  • Can also disrupt the link flow when websites link to your non-www domain when in fact you prefer www domain.

In case you are wondering, here is how to redirect non-www URLs to www URLs in WordPress.

Redirect Non-WWW URLs to WWW from cPanel

Using the cPanel to redirect non-www URLs to www URLs is one of the easiest ways.

To start off, log into your web host’s cPanel. Once you are here, find the Domains section and then select the option “Redirects.”

redirect-non-www-to-www-cpanel-redirects

The above action will open the Redirects page where you can manage all your redirections. Here, configure the settings as detailed below.

  1. From the drop-down menu next to “Type,” select the option “Permanent (301).”
  2. Here on the next line, select your domain from the drop-down menu.
  3. On the next line, enter your domain name as http://www.example.com. Of course, replace example.com with your actual domain name.
  4. Now, select the radio button “Do not redirect www” in the next line.
  5. After selecting the radio button, click on the button “Add” to add the redirect.

redirect-non-www-to-www-configure-cpanel-www-redirect-settings

That’s all there is to do. From this point forward, all your non-www URLs will be redirected to www URLs. For instance, if a user or search engine tries to access example.com, they will be redirected to www.example.com.

Redirect Non-WWW URLs to WWW Using .htaccess

Note: before editing the .htaccess file, make a backup of it. It helps you in restoring the file if needed.

If you don’t have access to the cPanel or if you just want to use a simple .htaccess rule then you can do that too.

To start off, log into your website’s FTP client, navigate to the root folder, find the .htaccess file and open it. If you cannot see the file, configure your FTP client to show hidden files.

redirect-non-www-to-www-open-htaccess-file

After opening the .htaccess file, copy the below code and paste it on the top of the file, save it and then reupload it. Don’t forget to replace example.com with your actual domain name.

#Redirect non-www URLs to www URLs in WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

That’s all there is to do. With the new .htaccess rule, you are successfully redirecting non-www URLs to www URLs.

Hope that helps and do comment below sharing your thoughts and experiences about using the above methods to redirect non-www URLs to www URLs in WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.