Choosing one canonical domain format and redirecting every other version to it prevents avoidable URL duplication, inconsistent analytics, and confusing user journeys. This checklist explains how to select between HTTPS, HTTP, www, and non-www, then implement and test a clean URL redirect using common web servers, Cloudflare, and CMS platforms.
Overview
A domain can be requested through several technically different addresses, including http://example.com, http://www.example.com, https://example.com, and https://www.example.com. If more than one version serves the same content, visitors, crawlers, analytics systems, and third-party links may encounter multiple representations of one page.
The practical solution is to choose one preferred format and make the others redirect to it. For most modern websites, HTTPS should be the required protocol because it encrypts the connection. The remaining decision is whether the canonical hostname should include www.
Neither www nor non-www is automatically better for every site. A non-www hostname is shorter and often used by smaller sites. The www version can make the website hostname distinct from the bare domain, which may be useful when the root domain also supports other services. Choose the format that fits your DNS, hosting, cookies, email, and organizational setup, then apply it consistently.
| Requested URL | Preferred URL | Expected action |
|---|---|---|
| HTTP, non-www | HTTPS, chosen hostname | Permanent redirect |
| HTTP, www | HTTPS, chosen hostname | Permanent redirect |
| HTTPS, alternate hostname | HTTPS, chosen hostname | Permanent redirect |
| HTTPS, chosen hostname | Same URL | Serve the page directly |
For a lasting protocol or hostname change, use a permanent server-side redirect, commonly a 301 or an equivalent permanent redirect supported by your platform. Temporary redirects are intended for situations where the original URL may become active again. Do not use a redirect as a substitute for a canonical tag: a redirect removes the alternate request path from the normal user journey, while a canonical link helps indicate a preferred version among pages that remain accessible.
A clean request flow should look like this:
- A visitor requests
http://www.example.com/page. - The server or edge layer redirects directly to
https://example.com/page. - The browser requests the final HTTPS URL.
- The final URL returns the page with an appropriate canonical link, if your site uses canonical tags.
Where possible, make the first redirect go directly to the final URL. Avoid sending a request through HTTP to HTTPS, then www to non-www, then through another application redirect.
Checklist by scenario
Before changing the rule
- Choose one preferred URL format, such as
https://example.comorhttps://www.example.com. - Confirm that both the preferred and alternate hostnames resolve to infrastructure you control.
- Install and test a valid certificate for every HTTPS hostname that visitors might request, including the alternate hostname when it must redirect.
- Confirm that the hosting platform accepts requests for the old format; a DNS record alone does not create an HTTP redirect.
- Record the intended behavior in a short redirect specification so developers, editors, and hosting administrators use the same rule.
Apache and .htaccess
On Apache, the rule can be placed in the appropriate virtual host configuration or, where enabled and suitable, in the document root's .htaccess file. The exact syntax depends on the server modules and hosting setup, so test in a non-production environment first.
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]This example treats https://example.com as the preferred format. The host pattern must be changed to match your selected hostname. Preserve the path and, unless your application requires different handling, allow the query string to pass through. If the site already has rewrite rules for a CMS, place the canonicalization logic where it will not conflict with application routing.
Nginx
With Nginx, use a dedicated server block for alternate requests and a separate block for the canonical HTTPS site. A typical alternate block redirects both protocol and hostname variants after the request reaches the server:
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 website rather than redirect. Configure certificates and server names according to your hosting environment. If the certificate is not available for an HTTPS alternate hostname, a browser may stop before it can receive the redirect, so certificate coverage must be tested separately.
Cloudflare or another edge layer
At an edge provider, create a redirect rule that matches requests using the non-preferred protocol or hostname and sends them directly to the final HTTPS URL. Preserve the path and decide deliberately whether query parameters should remain. Keep the origin server's rules aligned with the edge rule; duplicate logic can produce loops or unexpected status codes.
Check whether the edge service is proxying the relevant DNS records and whether the SSL mode matches the origin's configuration. An edge redirect cannot repair an origin certificate or routing problem if the request is terminated before the rule can run.
WordPress and other CMS platforms
Set the site URL and home URL to the same preferred HTTPS format, using the CMS's native settings where available. Update internal links, navigation, media references, feeds, and sitemap settings if they still output the old hostname. A redirect plugin may be useful for individual URL rules, but the basic HTTP-to-HTTPS and hostname policy is usually more reliable at the web server or edge layer.
After changing the CMS settings, clear application, page, CDN, and browser caches as appropriate. Confirm that the administrative area, login flow, images, scripts, stylesheets, and form submissions continue to use the preferred origin.
What to double-check
Use a redirect checker or command-line request tool to test every important variant. Test the homepage, a representative content page, a directory path, a URL with a query string, and a URL that should return an error. For each request, record the status code, Location header, number of hops, and final response.
- Directness: Every alternate version should reach the canonical URL in one redirect whenever practical.
- Path preservation:
/products/itemshould not unexpectedly become the homepage. - Query handling: Preserve campaign parameters when attribution requires them, but avoid copying unsafe or meaningless parameters indefinitely. Document any normalization policy.
- Port behavior: Check common HTTP and HTTPS ports if your infrastructure exposes them.
- Internal consistency: Navigation, XML sitemaps, structured data, hreflang references, feeds, and canonical tags should use the preferred format.
- Cookies and security: Review cookie domain, secure attributes, authentication callbacks, payment integrations, and third-party allowlists after changing hosts.
- External links: Important backlinks do not need to be individually changed before a redirect launches, but update links you control to reduce unnecessary hops.
- Monitoring: Review server logs and analytics for redirect loops, rising error responses, unexpected hostnames, and loss of campaign attribution.
Use a redirect chain checker during testing. A chain such as HTTP non-www to HTTPS non-www to HTTPS www is functional but less efficient than a single direct redirect. A loop usually results from conflicting rules at the CDN, web server, load balancer, or CMS. When debugging, temporarily identify which layer returns each response rather than changing several configurations at once.
Common mistakes
- Redirecting only the homepage: Canonicalization must apply to all paths, not just the root URL.
- Choosing a canonical hostname without checking DNS: The selected hostname must point to the service that can serve the site and its certificate.
- Using JavaScript or a meta refresh for the primary rule: Server-side or edge redirects provide a clearer, earlier response and avoid depending on page execution.
- Creating separate rules that fight each other: Consolidate protocol and hostname logic where possible.
- Forgetting HTTPS alternate-host certificates: A browser may report a certificate error before receiving a redirect.
- Hard-coding the wrong host in application code: Absolute URLs in templates, feeds, APIs, and structured data can recreate duplicate versions after the redirect is fixed.
- Redirecting every missing URL to the homepage: This hides broken links and can create poor user experiences. Map changed pages to their closest relevant replacements and return an appropriate not-found response when no replacement exists.
- Testing only while logged in: Caches, authentication, and administrative settings can conceal behavior that ordinary visitors experience.
For a broader migration, create a URL redirect map before deployment and test it in staging. The guide to building an SEO-safe redirect map covers how to organize old and new paths. If your rules also change query parameters, review when to preserve, strip, or normalize URL parameters.
When to revisit
Recheck the canonical URL setup before a seasonal planning cycle, hosting migration, domain alias launch, CMS upgrade, CDN change, or certificate renewal. It is also worth revisiting when analytics show traffic under an unexpected hostname, search tools report duplicate URL variants, or a redirect audit finds new chains and loops.
Keep a small test list in your deployment documentation:
- HTTP non-www homepage.
- HTTP www homepage.
- HTTPS alternate-host homepage.
- HTTPS canonical homepage.
- One deep path with a query string.
- One retired or invalid path.
Run that list after infrastructure or workflow changes and save the results with the release record. If behavior changes, identify the layer responsible, correct the rule, then retest caches and dependent integrations. A consistent canonical URL is not a one-time setting; it is a lightweight operational check that should remain part of domain, SEO, and website maintenance.
For related implementation work, compare domain forwarding with a true URL redirect in this domain forwarding guide, and use the staging redirect QA checklist before a production release.