Have you ever tried opening a site's address without www? I have, and often you land on an annoying error page, or on a copy of the site living its own life next to the official version. A site with or without www is first of all a matter of choice: one address displays the pages, the other sends the visitor there with a permanent redirect, and every other signal (canonical tag, sitemap, HTTPS) repeats the same choice.
Why having both addresses is a problem
To a browser as to a search engine, exemple.com and www.exemple.com are two distinct hosts. Technically, www is just a subdomain: nothing forces the two forms to display the same content, or even to both exist. Three situations occur:
- the address without www does not answer at all: the visitor who types it sees an error and leaves;
- both addresses display the same site without a redirect: every page exists twice;
- only one address displays the site and the other redirects to it: this is the situation to aim for.
Duplicate content: dilution rather than a penalty
For a long time, I wrote here that leaving both versions accessible exposed you to a Google penalty. That needs nuance. Google states in its Search Central documentation that a bit of duplicate content on a site is normal and is not a violation of its spam policies. The engine groups identical addresses and keeps only one, called the canonical.
The real issue lies elsewhere: if you do not say which version you prefer, Google chooses for you, and not necessarily the one you promote. The links the site receives are split between two addresses, as are the statistics, and crawler visits are scattered across duplicate pages. On a small site, the effect stays discreet; on a site with several thousand pages, it shows. The same logic applies to other forms of duplication, such as duplicate content on index.php or one site answering on several domain extensions.
With or without www: which version to keep?
Neither form ranks better with search engines. The choice comes down to practical criteria:
- without www: a shorter address, easier to say and remember, often chosen by recent sites;
- with www: a real subdomain, which makes some settings easier; the DNS standard does not allow a CNAME record at the root of a domain, which complicates connecting some content delivery networks (CDNs) to the short form;
- what already exists: if your site has been known for years under one form, keep it, the links and visitors' habits are already there.
What matters is consistency: the same form in your internal links, in your sitemap, on your business cards and in your social media profiles.
How Google weighs each signal
Google's documentation on consolidating duplicate URLs ranks the methods by strength, which explains why a redirect alone is not always enough and why a sitemap alone never is:
| Method | Strength according to Google | Role for a www choice |
|---|---|---|
| Permanent redirect | strong signal that the target should become canonical | the backbone: the unwanted form never displays a page |
| rel="canonical" tag | strong signal that the specified URL should become canonical | confirms the choice on every page, useful if a copy slips through |
| Inclusion in the sitemap | weak signal | only lists addresses of the chosen form |
When these signals contradict each other (a redirect towards www, a canonical tag pointing to the short form, a sitemap mixing both), Google has to arbitrate, and the result may not be the one you want. Aligning them is the whole job.
Setting up the permanent redirect
The permanent redirect (301 code) tells browsers and crawlers that the address has changed for good. Google treats it as a strong signal for designating the canonical address and recommends a permanent server-side redirect whenever possible. A temporary redirect does not do the same work: Googlebot follows it, but the indexing pipeline does not use it as a signal that the target should be canonical. A host interface set to "temporary" by default is therefore worth checking. The examples below send exemple.com to www.exemple.com, as I originally recommended; to do the opposite, just swap the two names.
Note: for the redirect to work, both names (with and without www) must point to your server. This is set in the DNS zone, with your domain name provider or your host. The SSL certificate must also cover both forms, otherwise the browser shows a security warning before the redirect even happens.
In PHP
The code goes at the very top of the file called by every page, often a shared header:
<?php
if ($_SERVER['HTTP_HOST'] === 'exemple.com') {
header('Location: https://www.exemple.com' . $_SERVER['REQUEST_URI'], true, 301);
exit();
}
?>
This version replaces the page's old example, whose typographic quotes stopped the code from working once copied.
In the .htaccess file (Apache)
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^exemple\.com$ [NC]
RewriteRule ^(.*)$ https://www.exemple.com/$1 [R=301,L]
The rule previously published here did not specify a destination address: it therefore redirected nowhere. The NC option makes the condition case-insensitive, and $1 copies the requested path so that each page lands on its twin, not on the home page. The same principle covers a full move, explained in redirecting an old URL or a whole site to a new address.
At your host or in the CMS
Many hosts offer the option in their interface, and WordPress redirects by itself to the address entered in its general settings. Check the result anyway: a server-side setting that contradicts the CMS one produces a redirect loop, and the site becomes inaccessible.
HTTPS and HSTS: the order of redirects matters
If you plan to add your domain to the HSTS preload list (the list built into browsers that forces HTTPS before any connection), its requirements constrain your www setup. The hstspreload.org project asks you to redirect from HTTP to HTTPS on the same host first, so http://exemple.com goes to https://exemple.com, and only then to the www form. It also requires HTTPS for the www subdomain if a DNS record exists for it, and the HSTS header must be served on the bare domain with a lifetime of at least one year, including all subdomains. In practice, that rules out jumping straight from http://exemple.com to https://www.exemple.com in one hop if preloading is your goal: accept two redirects on that single combination.
Check that everything is in order
- type the four combinations (http and https, with and without www): all must end up at the same address, ideally in a single redirect (the HSTS case above excepted);
- check that your internal links and your XML sitemap submitted to Google only use the chosen form;
- follow this same form in Google Search Console, and think about Bing indexing, whose webmaster tool deserves the same setting;
- add a canonical tag on each page pointing to the chosen address: it complements the redirect, without replacing it.
In Search Console, a Domain property is the simplest way to see both forms at once: Google's help states that it automatically includes the www and non-www prefixes, as well as the http and https protocols. It is verified only through a DNS record, which you add at the same place where you pointed both names to your server. A URL-prefix property, on the other hand, only shows the exact form entered, which makes it handy for confirming that the unwanted form no longer collects any clicks.
Finally, Google states that it prefers HTTPS pages over their HTTP equivalents when choosing the canonical address: take advantage of the redirect to send everyone to the secure version, with or without www as you choose.
Questions on the www choice and its redirect
Can I switch from www to the short form on an existing site?
Yes, as long as the switch is permanent and complete: every old address redirects to its twin under the new form, internal links, canonical tags and the sitemap are updated at the same time. Changing back and forth sends contradictory signals, so decide once.
Is a canonical tag enough without a redirect?
It is a strong signal for Google, but the visitor still sees two addresses, and links keep pointing to both. The redirect settles the question for humans and crawlers alike; the canonical tag backs it up.
Why does my redirect go to the home page instead of the right page?
The rule does not pass the requested path. In the .htaccess example, the $1 does that job; in PHP, it is the REQUEST_URI variable appended to the new host.




