HTTPS, www and Trailing Slash Redirect Rule Builder (Apache, Nginx)

Builds the redirect rules for one canonical version of your site: HTTPS or not, www or non-www, and a trailing slash policy that leaves file URLs alone.

Use the tool

Why this tool exists

Search engines see http://example.com, https://www.example.com and the slash and no-slash forms as different URLs. Redirecting all of them to one form keeps signals together and avoids duplicate pages.

The Apache rules send the scheme and host to the final address in a single hop and were tested against apache2 2.4 for the host and slash cases. HTTPS itself could not be tested locally, and Nginx output was not run. Adding a slash rule can still loop with some frameworks, so test with curl -I.

How to use it

  1. Enter your domain without www.
  2. Choose the preferred host, HTTPS and the slash policy.
  3. Pick Apache or Nginx and copy the rules.
  4. Test all four host and scheme combinations with and without a slash.

Frequently asked questions

Should I use www or non-www?

Either works. Pick one, redirect the other and use it in canonical tags and sitemaps.

Why skip file URLs for the slash rule?

A slash after /file.pdf would break it. The rule only touches paths without a file extension.

Why does it sometimes take two hops?

Scheme and host are fixed in one hop, then the slash rule can add a second. Many servers can combine them, but that needs server-specific logic.

What about a CDN or load balancer?

If it ends HTTPS for you, Apache may always see plain HTTP. Test the X-Forwarded-Proto header instead.