# 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.

Canonical: https://scaplet.com/seo/wordpress/www-redirect

Guide WordPress WordPress · Canonical hostname

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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fwordpress%2Fwww-redirect%20(%22WordPress%20www%20redirect%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fwordpress%2Fwww-redirect%20(%22WordPress%20www%20redirect%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fwordpress%2Fwww-redirect%20(%22WordPress%20www%20redirect%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fwordpress%2Fwww-redirect%20(%22WordPress%20www%20redirect%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 4 parts, 5 minutes.

1. [Four layers that decide the hostname 01](#four-layers-that-decide-the-hostname)
2. [Choose and set the preferred host 02](#choose-and-set-the-preferred-host)
3. [When WordPress alone is not enough 03](#when-wordpress-alone-is-not-enough)
4. [Check it worked 04](#check-it-worked)

_01_Which layer does what

## Four layers that decide the hostname

Layer

### Settings > General: `Site Address (URL)`

What it controls

The address you want people to type in their browser to reach the site. This is what the www choice is

Source

WordPress.org Settings General screen

Layer

### `WP_HOME` and `WP_SITEURL` in `wp-config.php`

What it controls

If defined, that value appears in the field and you cannot change it from the admin screen

Source

WordPress.org Settings General screen; Changing the Site URL

Layer

### `redirect_canonical()`

What it controls

Redirects incoming [www or non-www](/glossary/www-vs-non-www) requests to the host in `home_url()`, in PHP, once the request reaches WordPress

Source

WordPress Developer Resources

Layer

### Web server config (Apache `Redirect`, `mod_rewrite`)

What it controls

Redirects before WordPress runs, for any path the server handles

Source

Apache HTTP Server documentation

The `redirect_canonical()` reference says search engines consider `www.somedomain.com` and `somedomain.com` to be two different URLs when they both go to the same location, and that the function redirects all [incoming links](/glossary/backlinks) to one or the other. Its source comments say it redirects only between no-www and yes-www, and ignores differences in host capitalization to avoid infinite redirects.

_02_How 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](/glossary/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' );
```

**Changing the address is a migration step**WordPress says these two settings control the URL in the admin and on the front end, and are used throughout its code. Take a backup before editing them, and expect to update links, sitemaps and canonical tags that name the old host.

_03_Your 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](/glossary/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](/glossary/http-status-codes) 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.

**Do not run two opposing rules**If the server sends `www` to the bare domain while the WordPress Site Address says `www`, the two redirects send visitors back and forth. [WordPress redirects](/seo/wordpress/redirects) to the host in `home_url()`, so the server rule and the setting must name the same host.

_04_How 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](/seo-issues/redirect-chains).
3. 3

### Compare the signals

The [canonical tag](/glossary/canonical-url), [internal links](/glossary/internal-links) and sitemap URLs should all use the preferred host. See [WordPress canonical tags](/seo/wordpress/canonical-tags) and [WordPress XML sitemap](/seo/wordpress/xml-sitemap).
4. 4

### Look for duplicates in Google

If both versions are already indexed, see [www vs non-www](/glossary/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](/seo/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. 01 [Settings General screen | WordPress.org Documentation](https://wordpress.org/documentation/article/settings-general-screen/) wordpress.org · checked 2026-11-01
2. 02 [Changing The Site URL (Migrating WordPress) | WordPress.org Documentation](https://wordpress.org/documentation/article/changing-the-site-url/) wordpress.org · checked 2026-11-01
3. 03 [redirect_canonical() | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/redirect_canonical/) developer.wordpress.org · checked 2026-11-01
4. 04 [What is URL canonicalization (consolidate duplicate URLs) | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls) developers.google.com · checked 2026-11-01
5. 05 [Redirects and Google Search | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/301-redirects) developers.google.com · checked 2026-11-01
6. 06 [Redirecting and Remapping with mod_rewrite | Apache HTTP Server](https://httpd.apache.org/docs/current/rewrite/remapping.html) httpd.apache.org · checked 2026-11-01
7. 07 [Server names | nginx documentation](https://nginx.org/en/docs/http/server_names.html) nginx.org · checked 2026-11-01

Questions

## Asked a lot.

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

_01_ Does 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.

_02_ Where 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.

_03_ Is 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.

## Keep learning

[All platform guides](/seo)

[Learn WordPress HTTPS CMS](/seo/wordpress/ssl) [Related www vs non-www Crawling and indexing](/glossary/www-vs-non-www) [Read next WordPress canonical tags CMS](/seo/wordpress/canonical-tags) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Yoast SEO breadcrumbs](/seo/yoast/breadcrumbs)

More in WordPress SEO
[AMP on WordPress](/seo/wordpress/amp) [Google Analytics on WordPress](/seo/wordpress/google-analytics) [How to put WordPress in maintenance mode](/seo/wordpress/maintenance-mode) [WordPress 404 page](/seo/wordpress/404) [WordPress AI crawlers](/seo/wordpress/ai-crawlers) [WordPress breadcrumbs](/seo/wordpress/breadcrumbs) [WordPress canonical tags](/seo/wordpress/canonical-tags) [WordPress Core Web Vitals](/seo/wordpress/core-web-vitals) [WordPress favicon](/seo/wordpress/favicon) [WordPress Google Search Console setup](/seo/wordpress/search-console) [WordPress hreflang and multilingual SEO](/seo/wordpress/hreflang) [WordPress HTTPS](/seo/wordpress/ssl) [WordPress image SEO](/seo/wordpress/image-seo) [WordPress internal links](/seo/wordpress/internal-links) [WordPress lazy loading](/seo/wordpress/lazy-loading) [WordPress noindex](/seo/wordpress/noindex) [WordPress redirects](/seo/wordpress/redirects) [WordPress robots.txt](/seo/wordpress/robots-txt) [WordPress SEO plugins](/seo/wordpress/seo-plugin) [WordPress SEO titles and meta descriptions](/seo/wordpress/title-and-meta) [WordPress speed optimization](/seo/wordpress/page-speed) [WordPress structured data](/seo/wordpress/structured-data) [WordPress www redirect](/seo/wordpress/www-redirect) [WordPress XML sitemap](/seo/wordpress/xml-sitemap)

Terms on this page
[www vs non-www](/glossary/www-vs-non-www) [Backlinks](/glossary/backlinks) [Trailing slash in URLs](/glossary/trailing-slash) [HTTPS](/glossary/https) [HTTP status codes](/glossary/http-status-codes) [Canonical URL](/glossary/canonical-url) [Internal links](/glossary/internal-links)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
