HomeBlogWordPress www vs non-www: How to Set Up the Redirect Correctly
Migration & Setup3 November 20266 min read

WordPress www vs non-www: How to Set Up the Redirect Correctly

Pick one address, make the other 301-redirect to it, and keep WordPress, the server and the certificate in agreement. Here is how, with Nginx and Apache examples.

↪️

Short answer: choose one version of your address, for example example.com, and send every visit to the other one (www.example.com) to it with a single 301 redirect. Set the same version in WordPress under Settings → General, make sure your SSL certificate covers both names, and check that only one layer (WordPress, the web server or Cloudflare) does the redirecting.

Does it matter which one you pick?

Not for ranking. Google treats www and non-www as two different addresses, so what matters is that you use one consistently and redirect the other. Pick the one your links, email signatures and printed material already use. Changing later means another round of redirects.

Step by step

  1. 1In Settings → General, set WordPress Address (URL) and Site Address (URL) to the version you chose, with https://.
  2. 2Make sure DNS has records for both names: an A record for the bare domain and an A record or CNAME for www.
  3. 3Make sure the SSL certificate lists both names. Open https://www. and https:// without www; neither may show a certificate warning.
  4. 4Add one 301 redirect on the web server from the other name to your chosen one (examples below).
  5. 5Test with curl -I on all four combinations: http and https, with and without www. Each should reach the final address in one hop.
  6. 6In Google Search Console, use a Domain property, or add both versions, and submit the sitemap of the version you kept.

Nginx: redirect www to non-www

nginx
server {
    listen 443 ssl;
    server_name www.example.com;
    # ssl_certificate lines for a certificate that covers www.example.com
    return 301 https://example.com$request_uri;
}

Apache (.htaccess): redirect www to non-www

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

Nginx ignores .htaccess files. If your host runs Nginx, an .htaccess rule does nothing; the redirect has to go in the server configuration or the hosting panel.

Common mistakes

SymptomCauseFix
ERR_TOO_MANY_REDIRECTSWordPress sends to www, the server sends back to non-wwwMake Settings → General match the server rule
Certificate warning on www onlyCertificate issued for the bare domain onlyReissue the certificate for both names
Two hops (http → https → non-www)Separate rules for HTTPS and for wwwFine for visitors; combine into one rule if you can
Old links still show www in GoogleGoogle has not recrawled yetKeep the 301 permanently; it settles in weeks

On GHP Cloud

Every site is created for both the bare domain and www, and the certificate is requested for both names. If www DNS is not ready yet, GHP issues what it can and retries until both are covered, so the redirect never lands on a certificate error. WordPress then redirects to whichever address you set in Settings → General.

Frequently asked questions

Should I use www or non-www for SEO?

Either. Search engines rank them the same. Use one consistently and 301-redirect the other.

Should the redirect be 301 or 302?

301, because the move is permanent. A 302 tells search engines the old address may come back.

Why do I get "too many redirects" after adding the rule?

Two layers disagree: WordPress, the server or Cloudflare is redirecting the opposite way. Make all of them point to the same address.

G

GHP Team

GHP Cloud

Manage WordPress sites the smart way

GHP Cloud gives you a managed server in India with a firewall, malware scanning and daily backups, billed in INR with a GST invoice — from ₹1,450/month.