A clean canonical URL setup sends every HTTP, HTTPS, www, and non-www variation to one preferred address without loops or unnecessary redirect hops. This checklist explains how to choose the canonical host, configure an HTTP to HTTPS redirect, implement www or non-www forwarding, verify Apache, Nginx, Cloudflare, and CMS setups, and keep internal signals consistent after the change.
Overview
Most websites can be reached through four basic combinations: http://example.com, http://www.example.com, https://example.com, and https://www.example.com. If more than one version responds with page content, search engines, browsers, analytics tools, and users may encounter duplicate URLs. The goal is not to make every variation independently functional. The goal is to select one canonical URL format and redirect the other variants to it.
For example, a site may choose https://www.example.com as its preferred format. In that case, all four combinations should resolve to the same path on that host:
| Requested URL | Expected result |
|---|---|
| http://example.com/page | 301 redirect to https://www.example.com/page |
| http://www.example.com/page | 301 redirect to https://www.example.com/page |
| https://example.com/page | 301 redirect to https://www.example.com/page |
| https://www.example.com/page | 200 response, assuming the page exists |
Use a permanent redirect when the preferred URL is the lasting destination. A 301 is commonly used for this purpose, while a 302 or 307 is better reserved for a genuinely temporary condition. The status code is only one part of the setup: the destination, redirect chain, certificate, internal links, sitemap, canonical tags, and application behavior must also agree. For a broader explanation of status codes, see 301 vs 302 vs 307 Redirects.
Checklist by scenario
Before changing the redirect
- Choose one canonical format: HTTPS with www or HTTPS without www.
- Confirm that DNS records for the intended host and redirecting host point to infrastructure that can answer requests.
- Install and test a valid certificate for every HTTPS hostname that users may request, including the redirecting hostname.
- Record the current behavior for representative URLs, including the home page, a deep page, a URL with a trailing slash, and a URL with query parameters.
- Decide how query strings should be handled. Preserve campaign parameters when they are needed for attribution, but do not allow tracking parameters to create uncontrolled duplicate page URLs.
Apache and .htaccess
For an Apache site, the rule should test the scheme and host and then issue one destination. A common pattern for choosing the non-www HTTPS version is:
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
Place the rule where it runs before application routing, and adapt the hostname to the real domain. Test whether the hosting environment already adds an HTTPS or host redirect; duplicate rules at the web server, CMS, and plugin layers can create chains or loops. If the site uses a reverse proxy, confirm how the proxy communicates the original scheme before relying on %{HTTPS}.
Nginx
Nginx configurations are often clearest when redirecting noncanonical requests in a dedicated server block and serving the canonical host separately:
server {
listen 80;
server_name example.com 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;
}
The canonical HTTPS server block should serve the application and should not redirect back to either HTTP or www. The TLS certificate and virtual-host configuration must cover the host that receives HTTPS requests, including the www hostname if it redirects at HTTPS.
Cloudflare or another CDN
At a CDN, implement the rule at the edge only if the DNS and proxy arrangement supports that behavior. Create a single rule that checks for either HTTP or the noncanonical host and sends the request to the canonical scheme and host while retaining the path. If the interface offers separate “always use HTTPS” and hostname redirect controls, understand their order before enabling both. Two independent rules may produce an extra hop.
The origin must still be configured correctly. A CDN rule does not automatically make the origin certificate valid, and a proxy can create a redirect loop when the origin believes a request is HTTP even though the visitor connected over HTTPS. Check the provider’s current documentation and use its supported method for detecting the original protocol.
WordPress and other CMS setups
Update the CMS site URL and home URL, where applicable, to the same canonical HTTPS address. Then check the server, hosting panel, CDN, and redirect plugins for overlapping rules. Replace hard-coded HTTP links in themes, templates, menus, feeds, structured data, and content where practical. A CMS setting alone may not redirect requests that are handled before the application, while a server rule alone may leave generated links pointing to the old format.
For a larger hostname change or rebrand, maintain a URL mapping file rather than relying only on a global host redirect. The website migration redirect mapping checklist is useful when paths are changing as well as the protocol or host.
Canonical versus redirect: use each for the right job
| Control | What it does | When to use it |
|---|---|---|
| 301 redirect | Sends the browser and crawler to another URL and prevents the old URL from being the normal destination. | For a permanent protocol, hostname, or page-location change. |
| Canonical link element | Signals the preferred version while allowing the requested URL to remain accessible. | For legitimate accessible variants, such as certain parameterized or syndicated URLs. |
| Internal link | Directs users and crawlers to the URL your site intends to promote. | Always use the canonical format in navigation, content, feeds, and templates. |
| Sitemap entry | Lists URLs that the site considers preferred and discoverable. | Include only canonical, indexable HTTPS URLs. |
A canonical tag is not a substitute for an HTTP to HTTPS redirect when the old protocol or hostname should no longer be used. Conversely, do not redirect every parameterized URL if those URLs serve a valid purpose. Decide whether the variation should remain accessible, be canonicalized, or redirect to a specific equivalent.
What to double-check
Certificate and mixed-content readiness
Test HTTPS directly on the canonical host and on every host that should redirect. A certificate error can prevent the redirect from being reached. After enabling HTTPS, inspect browser developer tools or a crawl for images, scripts, stylesheets, fonts, embeds, and API calls still requested over HTTP. Update absolute URLs and application settings rather than masking the issue with a browser-side workaround.
Redirect path and response behavior
Use a redirect checker or command-line request to test each matrix combination and several paths. The ideal result is one redirect from a noncanonical request directly to the canonical URL, followed by a successful page response. Investigate any 200 response on a noncanonical host, more than one redirect hop, a 4xx or 5xx response, or a destination that changes the path unexpectedly.
curl -I http://www.example.com/sample-page
curl -I https://example.com/sample-page
curl -IL http://example.com/sample-page
The -L option follows redirects; use it to inspect the complete chain. Test with and without a query string, and confirm that required UTM parameters are retained or intentionally removed. A redirect checker can reveal behavior from outside your browser’s cache.
Internal SEO signals
- Update internal links, navigation, hreflang references, structured data, RSS feeds, and downloadable references where they contain absolute URLs.
- Regenerate the XML sitemap so it contains only canonical HTTPS URLs.
- Confirm that canonical tags point to the final URL, not an HTTP or noncanonical intermediate.
- Review robots directives. Do not use robots.txt to hide redirecting URLs that need to be discovered and processed.
- Check analytics and tag-manager settings so a protocol or host change does not split sessions or attribution.
After deployment, crawl a sample or the full site and review server logs where available. Look for repeated requests to HTTP URLs, old hostnames, redirect chains, and failed destinations. A recurring redirect audit is more reliable than a one-time browser check; see redirect monitoring metrics for a repeatable review structure.
Common mistakes
- Redirecting in stages: HTTP goes to HTTPS, then non-www goes to www. Combine the conditions so the request reaches the final URL in one hop.
- Creating a proxy loop: The CDN receives HTTPS, connects to the origin over HTTP, and the origin repeatedly redirects to HTTPS. Align proxy mode, origin settings, and forwarded-protocol handling.
- Missing a certificate on the redirect host: A request to HTTPS www cannot reach a redirect if the certificate covers only the non-www name.
- Using JavaScript or a meta refresh: Server-side redirects are more dependable for canonicalization, accessibility, and crawler processing.
- Leaving old absolute links in templates: Redirects may conceal the problem while adding needless requests and complicating reporting.
- Redirecting unrelated pages to the home page: Map changed URLs to their closest relevant replacement. If no useful replacement exists, review the appropriate not-found response instead.
- Ignoring caches: Permanent redirects can be cached by browsers, CDNs, and intermediary systems. Validate in more than one environment and plan changes carefully; the 301 redirect caching guide covers diagnosis and control.
When to revisit
Recheck the canonical URL setup before a seasonal campaign, site migration, domain rebrand, CMS change, hosting move, DNS update, certificate renewal, or CDN rule change. It is also worth reviewing after a major template release, analytics implementation, or unexplained crawl and traffic change.
Keep a small test list containing the four protocol-and-host combinations, a representative deep URL, a URL with parameters, and a deliberately missing URL. Run it after each infrastructure change. Confirm that every noncanonical version reaches the intended HTTPS host in one step, that the final response is correct, and that the page’s canonical tag, internal links, and sitemap entry agree.
When the underlying platform or CDN changes its rule interface, do not copy an old configuration blindly. Recheck the provider’s current syntax, proxy behavior, certificate requirements, and rule order in a staging or narrowly scoped environment first. A clean canonical setup is not a set-and-forget switch; it is a small, testable part of ongoing technical SEO and link management.