07887 423199me@richieaubin.com

Standardise HTTPS, www and trailing slashes

Choose one preferred version of your public addresses. Apply the same convention in server rules, internal links, canonical tags and sitemap entries.

Preferred URL routing example
Example image · CC0 1.0 licence

Choose a way to do this check

Browser Network

  1. Test each scheme and hostname with Preserve log enabled.
  2. Record the first response and check that the intended HTTPS host stays on its preferred path.

Screaming Frog List mode

  1. Upload slash, host and scheme variants with known expected destinations.
  2. Export redirects and compare each chain, including a query-string case and unaffected resource.

Response headers

  1. Paste the resulting header chain to locate each Location value.
  2. If an HTTPS request never gets a status, inspect the certificate first.

1. List all publicly reachable variants

Check HTTP and HTTPS for both the www and non-www hosts. Include the homepage, a deeper page and an asset. If the HTTPS version of an alternate hostname should redirect, it still needs a valid certificate, because TLS is negotiated before the redirect can be sent.

Record where requests first land. If a CDN handles TLS and forwards HTTP to the origin, a scheme rule at the origin can loop if it ignores the trusted proxy configuration. Configure the redirect at the layer that can reliably tell which external host and scheme the visitor used.

2. Redirect alternate hosts to a fixed preferred host

This Nginx example assumes TLS terminates at Nginx or an HTTPS listener for the alternate host is already configured separately. The port 80 block preserves the request path and query string and uses a fixed destination host. Merge it with your existing host configuration. Check the preferred HTTPS site and certificate first.

Nginx · HTTP virtual host
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;
}

If https://example.com/ also serves traffic, apply the corresponding redirect in its existing TLS server block. Keep its certificate and relevant listener settings. Use a staging test for both hosts. Do not configure the same unconditional redirect on the preferred HTTPS block.

3. Add a scoped trailing-slash rule

Check which address the application already considers final. An API route, file and HTML directory may have different conventions. Start with an exact location on the preferred host rather than rewriting every path. The example below applies only to one HTML route and deliberately retains query parameters.

Nginx · exact match inside the preferred HTTPS server
location = /guides {
    return 301 https://www.example.com/guides/$is_args$args;
}

With separate host and slash rules, some combinations can create two hops. If this affects important inbound links, handle the relevant path variations together at the edge or in an explicit mapping. Confirm that this optimisation does not alter paths with functional query strings or route-like asset URLs.

4. Test the variants and align references

Run nginx -t before reloading, then check the first status and final result. Expand the list for your production templates. A URL already in the preferred form should return its normal response without another redirect.

Terminal · compare three variants
for url in 'http://example.com/guides?q=sample' \
  'https://example.com/guides/' 'https://www.example.com/guides/'; do
  curl -sSL --max-redirs 5 --max-time 20 -o /dev/null \
    -w '%{http_code} %{num_redirects} %{url_effective}\n' "$url"
done

Verify a file and an API or form route where applicable before publishing a broad normalisation rule. Update application links, canonicals and sitemaps to the preferred address so normal site journeys do not depend on redirects. Keep the previous configuration available to restore if a rule changes unaffected requests.

Technical references

Frequently asked questions

Should I choose www or non-www for rankings?

Choose the version that fits the operational setup and existing canonical URLs. Apply it consistently.

Why does HTTPS need a certificate before the redirect?

The browser must establish the secure connection before it can read an HTTP response.

Should I force a slash on all URLs?

No. Scope the rule to known HTML routes and check how the application handles files and API routes.

Do redirects replace internal link updates?

Update internal links to the final URL and keep the redirects for older external links and bookmarks.

Written by Richie Aubin

Published