How to Redirect WWW to Non-WWW on a WordPress Website

When setting up a WordPress website, one of the important technical SEO steps is choosing whether your site should load with www (e.g., www.example.com) or without it (example.com). After choosing your preferred version, you must set up a proper redirect so your visitors, search engines, and external links all point to the same URL.

This article explains how to redirect www → non-www on a WordPress site, step by step.


1. Choose Your Preferred Domain Version

Before creating redirects, decide which version you want:

This guide focuses on redirecting www to non-www.


2. Update WordPress URL Settings

In your WordPress admin panel:

  1. Go to Settings → General
  2. Update the following fields to the non-www version:
    • WordPress Address (URL): https://example.com
    • Site Address (URL): https://example.com
  3. Save the changes

This instructs WordPress to use your chosen domain version.


3. Set Up Redirect in .htaccess (Apache Servers)

If your hosting uses Apache, you can easily set up the redirect in the .htaccess file located in the root directory of your WordPress site.

Add this code above the WordPress rules:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

This does the following:


4. Redirect via NGINX Configuration (NGINX Servers)

If your site runs on NGINX, you need to add a redirect rule in your server configuration:

server {
    listen 80;
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

Then reload NGINX:

sudo systemctl reload nginx

5. Update Your DNS Settings (Optional but Recommended)

To avoid conflicts, make sure your DNS records are correct:

This ensures all www traffic flows through your main domain.


6. Fix Hardcoded WWW URLs

Some links, images, or scripts may still be using the www version.

You can fix this using one of these:

Option 1: Plugin

Use Better Search Replace to replace:

Option 2: Manually update theme or plugin files

If you have custom code or hardcoded links, update them to the non-www version.


7. Test Your Redirect

Check that everything works:

Both should automatically redirect to:

https://example.com

You can also use tools like:


Conclusion

Redirecting www to non-www on your WordPress site is an important step for:

By updating your WordPress settings, configuring .htaccess or NGINX rules, and ensuring DNS and internal links match your preferred domain, you create a clean and professional setup for your website.