Consistency is a crucial factor in establishing a professional and user-friendly website. When it comes to websites, URL consistency plays a vital role in both SEO and user experience. Having two versions of your site—one with “www” and one without—can lead to duplicate content issues, dilute your search engine rankings, and confuse your visitors. Redirecting non-www URLs to www in WordPress ensures your website operates under a single, unified domain. Doing so is an essential SEO best practice, and fortunately, it’s easy to implement. Here's a detailed guide on how to do it.
Why Redirect Non-www URLs to www?
Search engines treat non-www (e.g., example.com
) and www (e.g., www.example.com
) as two separate websites. This can lead to:
Duplicate content penalties that affect your SEO rankings.
Split link equity, where backlinks are divided between the two versions of your site.
Confusion for users if they’re unsure which version of your site is the primary one.
By establishing a redirect, you ensure that all traffic is directed to one version, boosting your website's authority and improving the overall user experience.
Now, let's look at how you can achieve this.
How to Redirect Non-www to www in WordPress Using the .htaccess File
The .htaccess file is a powerful configuration tool used by Apache servers to manage rules and settings for your website. You can use it to set up a redirect from non-www to www. Here's a step-by-step guide:
Step 1: Access Your Website’s .htaccess File
To edit the .htaccess file, you’ll need to locate it on your server. You can do this in two ways:
Using an FTP Client
Log in to your website via an FTP client like FileZilla.
Navigate to your website’s root directory (typically called
public_html
orwww
).Look for the
.htaccess
file. If you don’t see it, ensure your FTP client is set to show hidden files.
Using the WordPress Dashboard
Install and activate a file management plugin like File Manager.
Access your .htaccess file directly from the plugin interface under the root directory.
Tip: Before you make any changes, always back up your .htaccess file to restore it if something goes wrong.
Step 2: Add the Redirect Code
Once you’ve accessed the .htaccess file, add the following code at the very top:
RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Replace example.com
with your actual domain name. Here's what this code does:
It turns on the rewrite engine (
RewriteEngine On
).Checks if the requested URL starts with the non-www version (
%{HTTP_HOST} ^example.com
).Redirects all such requests to the www version of your domain (
http://www.example.com
).
Step 3: Save Changes
After pasting the code, save the changes to your .htaccess file. If you’re using an FTP client, re-upload the file to your server.
Step 4: Test Your Redirect
Check if your redirect works correctly:
Open a browser and enter your site’s non-www version (e.g.,
http://example.com
).Verify that it redirects automatically to the www version (e.g.,
http://www.example.com
).
If it doesn’t work, double-check your .htaccess code for errors, or contact your hosting provider for assistance.
Alternative Method: Using a WordPress Plugin
If you’re not comfortable editing the .htaccess file, you can achieve the same result using plugins. Here are two reliable options:
This plugin is user-friendly and allows you to set up redirects without touching any code. Simply:
Install and activate the Redirection plugin.
Navigate to Tools > Redirection and set up a 301 redirect from the non-www URL to the www version.
2. All-in-One SEO or Yoast SEO
These plugins often include an option to set your website’s preferred domain, which can help standardize your URLs.
Plugins are convenient, but they can add unnecessary overhead to your website. Using .htaccess is a more performance-efficient option.
Final Tips for Testing and Ensuring Proper Redirection
Clear Browser Cache: Your redirect might not appear immediately if your browser has cached the non-www version.
Use Redirect Checker Tools: Online tools like Redirect Checker can confirm whether your 301 redirect is functioning correctly.
Check for HTTPS Compatibility: If your site uses HTTPS, make sure the redirect works for both HTTP and HTTPS versions of your site. Update the redirect code accordingly by replacing
http://
withhttps://
in the rule.
Wrap-Up
Redirecting non-www URLs to www in WordPress is an essential step for maintaining URL consistency, improving SEO, and delivering a seamless user experience. Whether you choose to edit the .htaccess file manually or use a plugin, this simple yet impactful fix strengthens your site’s online presence. Take a few moments to test your redirect and verify it’s working properly to ensure maximum benefits for both your visitors and search engines.
Stay consistent, optimize for SEO, and give your audience a navigation experience they can trust!