Free auditStart free
GuideWordPress · Canonical hostname

WordPress www redirect

Set the WordPress Site Address to www or non-www, see what redirect_canonical already does, and add a server redirect for what it skips. Test with curl.

5 min
read
7
sources
Oct 29, 2026
updated
Scaplet Editorial Team
author
In one line

Your Site Address (URL) in Settings > General decides the preferred hostname. WordPress core's redirect_canonical() then redirects requests for the www or non-www twin to that host. It skips admin, feeds, robots.txt, favicon.ico and POST requests, so add a permanent server redirect if other hostnames reach your site directly.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
02How it works

Choose and set the preferred host

  1. 1

    Pick one form and keep it

    Google's redirect guide says that when a site is reachable several ways, it is a good idea to pick one URL as your preferred (canonical) destination and use redirects to send traffic from the others. It does not say which form is better, so choose the one your DNS and certificate already cover, then do not flip it later without a reason.

  2. 2

    Open Settings > General

    Set Site Address (URL) to the exact form you want, for example https://www.example.com. WordPress says both settings should include https:// and have no trailing slash.

  3. 3

    Match the WordPress Address

    WordPress Address (URL) is where the core files live. WordPress says the two are identical unless you give WordPress its own directory, so a www change normally means updating both.

  4. 4

    Check for hard-coded constants

    If WP_SITEURL or WP_HOME is defined in wp-config.php, the field shows that value and is locked. Edit the constants instead, using the form WordPress documents.

  5. 5

    Save and re-test

    After saving, confirm you can still reach wp-admin. WordPress warns that people who change these fields sometimes find the site no longer works properly and have to fix the values by other means.

wp-config.php: hard-coded form from the WordPress docs
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );
03Your call

When WordPress alone is not enough

If this fits

Add a server redirect if

  • The other hostname can be answered by something other than WordPress, such as a separate virtual host, a static file or another app
  • You want the redirect to apply to paths WordPress skips: admin URLs, feeds, trackbacks, searches, robots.txt and favicon.ico
  • Requests are not GET or HEAD, since redirect_canonical() returns early for other methods
Or

Rely on WordPress alone if

  • Both hostnames already point at the same WordPress install and normal page requests reach PHP
  • curl shows a single 301 to your chosen host on a post and the home page
  • You do not control the web server config

Apache's rewrite guide says the best way to force one hostname does not involve mod_rewrite at all, and instead uses the Redirect directive in a virtual host for the non-canonical hostnames. Google's redirect guide gives the permanent form, Redirect permanent "/old" "https://example.com/new". Combined, for a site that should live on the www host (this catches port 80 only, as in Apache's example, so the bare domain's HTTPS virtual host needs its own Redirect):

Apache virtual host, adapted from the Apache and Google docs
<VirtualHost *:80>
  ServerName example.com
  Redirect permanent "/" "https://www.example.com/"
</VirtualHost>

For the reverse, Apache's guide shows how to strip the prefix with mod_rewrite by swapping the condition:

mod_rewrite: strip www (from the Apache docs)
RewriteCond "%{HTTP_HOST}" "^www\.(.+)$"              [NC]
RewriteRule "^(.*)"        "http://%1/$1"             [L,R,NE]

That recipe sends to http://, so on an HTTPS site change the scheme, then confirm the status code with the curl test below. Google recommends a permanent server-side redirect whenever possible, and says the 301 and 308 status codes mean a page has permanently moved. nginx matches hostnames through server_name (for example server_name example.org www.example.org;); the nginx page used here does not give a redirect recipe, so use your host's guidance.

04How it works

Check it worked

  1. 1

    Request the wrong host

    Run curl -sIL http://example.com/ | grep -i -E '^(HTTP|location)', swapping in the non-preferred host. You want one hop to the preferred host. Repeat on a post URL, not only the home page.

  2. 2

    Request the preferred host

    It should return 200 with no redirect to the other form. Repeat for https:// and http:// variants and count the hops. Fewer is better; see redirect chains.

  3. 3

    Compare the signals

    The canonical tag, internal links and sitemap URLs should all use the preferred host. See WordPress canonical tags and WordPress XML sitemap.

  4. 4

    Look for duplicates in Google

    If both versions are already indexed, see www vs non-www. Google lists redirects as a strong signal that the target should become canonical.

For ordinary page moves instead of the hostname, use WordPress redirects.

Sources · 7

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • wordpress.org
  • google.com
  • apache.org
  • nginx.org
  1. 01Settings General screen | WordPress.org Documentationwordpress.org · checked 2026-11-01
  2. 02Changing The Site URL (Migrating WordPress) | WordPress.org Documentationwordpress.org · checked 2026-11-01
  3. 03redirect_canonical() | WordPress Developer Resourcesdeveloper.wordpress.org · checked 2026-11-01
  4. 04What is URL canonicalization (consolidate duplicate URLs) | Google Search Centraldevelopers.google.com · checked 2026-11-01
  5. 05Redirects and Google Search | Google Search Centraldevelopers.google.com · checked 2026-11-01
  6. 06Redirecting and Remapping with mod_rewrite | Apache HTTP Serverhttpd.apache.org · checked 2026-11-01
  7. 07Server names | nginx documentationnginx.org · checked 2026-11-01
Questions

Asked a lot.

3 questions people ask next, answered from the sources on this page.

01Does WordPress redirect www to non-www automatically?

Its redirect_canonical() function redirects between the www and non-www form to match the host in home_url(), which follows your Site Address. It does not redirect admin, feeds, trackbacks, searches, robots.txt, favicon.ico, or POST requests.

02Where do I set www or non-www in WordPress?

In Settings > General, use the Site Address (URL) field. If WP_HOME or WP_SITEURL is defined in wp-config.php, the field is locked and you edit the constants.

03Is www or non-www better for SEO?

Google's redirect guide says to pick one preferred URL and use redirects to send traffic from the others. It does not name one form as better.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane