Share on

Table of Contents

profile-pic (1)
Mansoor Ahmad
November 18, 2024

Four Ways to Redirect www to Non-www of WordPress Website

People rarely use the ‘www’ standard for writing URLs today. Instead, they prefer to write the URL’s name and its domain type in search engines and press enter. 

Google treats www.url.com and url.com as separate ways to enter a website. When this happens, it also indexes them separately and as a result, two versions of the same website get indexed on Google. 

WWW & Non-WWW – Two Different Websites?

The www and non-www versions act as two different websites on Google, and it hurts the SEO efforts of the website administrators. 

  • Two versions increase crawl budget
  • Decrease site indexing
  • Creates duplicate content on search results
  • Confuses bots and users
  • Leads to fewer SERPs in search engines

The solution to WWW & Non-WWW Problem

Redirecting requests from www to non-www or vice versa is the best way to avoid duplicate indexing by search results. A single entry to the website will improve both the SEO efforts and user experience.

In this article, we will be discussing some of the best ways to fix the www & non-www indexing problems of your website. 

  1. HTAccess to Redirect www to non-www
  2. DNS Settings to Redirect www to non-www
  3. Using WordPress Settings to Redirect www to non-www
  4. Plugins to Redirect www to non-www in WordPress

301 Permanent Redirect for Preferred Website Address

When redirecting from www to non-www, you will be using the 301 redirects because it is a permanent redirect and it tells the search engines and user browsers that the address has been permanently moved to a new address. 

An example would be: Let’s say you type www.facebook.com in the search browser.

The browser automatically translates it to facebook.com and then shows you the login page.

It is because Facebook uses a permanent redirect where the WWW version of the website is permanently redirected to the non-WWW version.

Advantages of Moving WWW to Non-WWW

  • Non-WWW website is small and a lot easier to remember
  • People prefer to write website address just as they write queries in Google search
  • The majority of website owners now use the non-www standard for their websites

Which One Does Google prefer? WWW or Non-WWW

Google is indifferent to both the www and the non-www versions. A Twitter user asked John Mueller, Chief Search Engine officer of Google, this question. Whether Google prefers the www or non-www version for search indexing? John Mueller said that it doesn’t matter which version you use because Google can index both of them. Below is an image of the attached conversation.

Method 1: Use Htaccess to Redirect www to non-www or vice versa

You can direct from www to non-www or vice versa using the htaccess website. It is a simple and effective method to redirect URL traffic. 

Here is what you need to go:

You will need to have access to the htaccess of your website. If you have access to cPanel or the public_html folder of your website, you can easily start the htaccess file. It is available as a ‘.htaccess’ file in the search engine.

If you are using SSH or FTP, you can find the public_html directory and then search for the .htaccess file.

What if the .htaccess file is not available?

The .htaccess file should be available in the public_html folder. If it is not available in that folder then you need to create it. You can easily create it by writing the following code in a file.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Now save this file as ‘.htaccess’ and place it in the public_html folder.

Adding WWW to Non-WWW Redirect in .HTACCESS

Now that the htaccess file is created, you will need to add the following code to make it redirect from www to non-www website.

From www to non-www

If you want to display the non-www version only. Let’s say facebook.com instead of www.facebook.com then you use the following code.

RewriteEngine onRewriteCond %{HTTP_HOST} ^www.domain.com [NC]RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301,NC]

From non-www to www

If you want to display the www version instead of the www version. Let’s say www.facebook.com instead of facebook.com then you use the following code.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301,NC]

Simply add the following code to your htaccess file and then save it. Now, type the URL in the browser and it will automatically redirect to the right version on your WordPress website.

That’s it. You can now display the www or the non-www version of your website without a problem. 

Method 2: Changing www to non-www in DNS Settings

You can also change the site preferred URL from www to non-www or vice versa from the DNS settings of your domain address. So, open the DNS settings page and then add A records for both addresses. You will need A record for each name i.e., www.url.com and url.com.

Now once both the records are created, the A record section for your domain would look something like the image above.

Now, create a CNAME record to point your IP address to the actual domain name. Here is how you should do that.

NAME TYPE VALUE————————————————–www.example.com. CNAME example.com

In this example, we have used CNAME as an alias of the www version. So, when the user types the www version of the domain on the browser, it will automatically redirect to the main URL. 

Should You Use CNAME or htaccess to Redirect www to non-www

It really depends on your need. CNAME is an alias and it masks the official A record to the other A record. It is not a 301 redirect so Google will still index the www version of the website. If you want that Google doesn’t index the www version then you would need to create a 301 redirection apart from the domain masking using CNAME.

With that said, here is how you can redirect the version in WordPress.

Method 3: WWW to Non-WWW in WordPress

WordPress offers a fairly simple way to redirect a website from a www version to a non-www version. The best part about it is that you can easily redirect the website without downloading any additional plugins. 

If you don’t have an htaccess file, you can just use WordPress to do it. Here is how you can start:

  1. First, go to WordPress Settings page

You can go to the settings page by signing into the WordPress dashboard. WordPress offers Site Address URL and the WordPress Address URL. Site Address is the official address that will be indexed on Google. It is the address that you will publish or ensure as a brand. 

However, the WordPress address is the address that shows on your WordPress website when someone types the address in the browser and hits enter.

Both are usually kept the same and it is a good practice to create coherence between the two.

In the above example, you can see that WordPress Address and Site Address start without www. This means that the website has a non-www address.

You can do the same for your website. You don’t have to add a redirection in HTaccess in this regard because WordPress automatically redirects the site address to the address typed in the input field.

For this specific method, you won’t need any third-party plugin because only the admin panel is needed to make the changes. 

Changing Non-WWW to WWW in WordPress Settings

Similarly, if you want to add www back to your WordPress website, you can simply add it in both the Site Address and WordPress Address URLs as is described in the url above. 

Once done, the website will automatically start to show the www version of your domain name. 

Note: Make sure that you keep only a single URL address and don’t change it often because it can directly impact your site rankings in the long run.

Accessing htaccess from WordPress

Another benefit of using WordPress is that you can directly access the htaccess file and make relevant changes to it without opening the Cpanel or hosting control panel.

Edit Htaccess file with Yoast Plugin

A simple way to edit the htaccess file in WordPress is to use Yoast file editor. Yoast offers a simple way for website owners to edit the htaccess file within WordPress. Users can just click on the Yoast File editor, and then edit the htaccess file with any changes they want to be done.

Simply click on Yoast SEO > Edit Files

Now you can either edit the Robots.txt file or the htaccess file. In our case, we want to edit the htaccess file through WordPress. Simply edit the changes on the file and then click Save. Yoast will automatically update the htaccess file. Press Ctrl+F5 to see the changes made to your WordPress website in your browser. That is it.

Use Htaccess File Editor Plugin in WordPress

Another way to edit the htaccess file in your WordPress website is with htaccess file editor. It is a separate plugin that you can use on your WordPress website to make the necessary changes to htaccess.

You can download the plugin directly from the WordPress plugins menu. The editor will provide a simple, safe & fast way to edit, fix & test the site’s htaccess file from WP admin. 

You can save the Htaccess backups as well. They can then be restored directly from the plugin. 

Once you have the htaccess file editor available, simply add the code that we provided above to make a redirect from www to the non-www website or vice versa. This will create a permanent redirection for your website. Google and other search engines will now only list one version of your website and this will boost your website rankings and improve the indexing of pages and posts.

Method 4: WWW to Non-WWW with WordPress Plugin

Another great way to redirect the website from www to non-www or vice versa is with the WordPress redirection plugin named All In One Redirection plugin. The plugin is pretty simple to use and allows anyone to make edits to the website as and when necessary.

  1. Simply download the All in One redirection plugin to your WordPress website. 

The plugin is mostly used for redirecting site pages and posts to a new address. But it can also be used to for HTTP to HTTPS and WWW to Non-WWW pages as well. 

You don’t have to make any changes in the htaccess file or to DNS records because the redirection plugin takes care of both. Since the redirections are plugins, they will still be applied even if the plugin is removed from your WordPress website. 

The method of using a WordPress plugin to make redirections to your website is perfect for all those who don’t want to make any changes to their website through htaccess or DNS records. This way, they can feel safe and still get the job done.

That’s it. We have provided four ways to redirect www to non-www or vice versa. All of these ways work flawlessly, and they allow you to easily redirect your website to the preferred version for proper website indexing and removal of duplicate pages from search results.

We hope that this way will help you improve your site health, promotion, and bring more quality visitors to your WordPress website.

Mansoor Ahmad

Mansoor Ahmad is a web developer and WordPress enthusiast. He has been building websites with WordPress since 2013. He is passionate about teaching and writing about WordPress and helping fellow web creators build better websites.

WPForms Review: Is It Really The Best Form Builder?

You have a website. Now you want to generate leads from people coming to your site. What can you do about it? You will need a form on your WordPress

Top 10+ Free Map Plugins for WordPress & WooCommerce

Want to integrate Google maps to your WordPress website? Fortunately, WordPress offers plenty of free plugins that you can use to easily embed Google/Bing/WikiMapia maps to your WordPress websites and

How To Fix HTTP Error When Uploading Images to WordPress

When uploading a file to WordPress you will often get the error ‘HTTP error’ file cannot be uploaded. The error is frustrating and it often has no solution. You try