Trailing Slash
Does a trailing slash matter for SEO? The root-domain exception, the file-vs-directory history, the REST API gotcha, and copy-pasteable Apache, Nginx, and IIS rules to enforce one format — plus when not to bother changing it.
1 evidence signal on this page
- Related live toolHTTP Status & Redirect Checker
A trailing slash is the / at the end of a URL. example.com and example.com/ are identical — that root-domain case is the one universal rule. Everywhere else, example.com/page and example.com/page/ are different URLs, so if both are live and neither consolidates you get duplicate URLs. It doesn't matter which format you pick; it matters that you pick one and enforce it with 301 redirects (the strong signal), backed by canonical tags, consistent internal links, and sitemap entries. Watch the file-path gotcha (page.html/ won't load), the REST API quirk (many frameworks treat /resource and /resource/ as distinct routes), double slashes, and redirect chains stacking with HTTPS/www. And per my usual advice: unless your setup is causing issues, I wouldn't force a change to your URLs.
Evidence for this claim Google treats slash and non-slash URLs as separate URLs, either of which can be canonical if behavior is consistent. Scope: Google's documented trailing-slash handling. Confidence: high · Verified: Google Search Central Blog: To slash or not to slash Evidence for this claim Under URI resolution rules, a trailing slash changes path-base semantics; server behavior still determines the HTTP resource returned. Scope: URI reference resolution, distinct from search-engine canonical choice. Confidence: high · Verified: IETF RFC 3986: Reference resolutionTL;DR — A trailing slash is the
/at the end of a URL —example.com/page/versusexample.com/page. On your homepage it makes no difference at all (example.com=example.com/). Everywhere else the two are different URLs to Google, so pick one format, redirect the other version to it, and link to it consistently. There’s no “right” choice — consistency is the whole game.
What a trailing slash is
A trailing slash is a forward slash at the very end of a web address:
example.com/page/ ← with a trailing slash
example.com/page ← without a trailing slashThat’s it. One character. But that one character can turn a single page into two different URLs in the eyes of a search engine.
The one exception: your homepage
There’s exactly one place the trailing slash truly doesn’t matter — the bare
root domain. example.com and example.com/ are treated as the same thing,
always. You can write it either way and Google sees the same URL. (There’s a
technical reason for that, covered in the Advanced tab, but the practical takeaway
is: don’t worry about the slash on your homepage.)
Everywhere else, it’s a different URL
Once there’s a path after the domain, the slash matters. example.com/shoes and
example.com/shoes/ are two separate URLs. If both load the same page and you
haven’t told search engines which one you prefer, you can end up with duplicate
URLs — the same content in two places, splitting its strength instead of pooling
it on one address.
What to actually do
You don’t need to agonize over which format is “better.” Both are fine. What matters is that you pick one and stick to it:
- Decide: slash or no slash.
- Make the other version redirect to your chosen one.
- Link to the chosen version everywhere on your own site.
- List only the chosen version in your XML sitemap.
One gotcha worth knowing even at this level: don’t assume adding a slash to a file-looking URL is harmless. It creates a different path, and whether it loads, redirects, or returns an error depends on the server and application.
Want the history behind the slash, the server-config snippets to enforce it on Apache, Nginx, and IIS, the REST API twist, and why I’d usually tell you not to change your URLs? Switch to the Advanced tab.
Evidence for this claim Google treats slash and non-slash URLs as separate URLs, either of which can be canonical if behavior is consistent. Scope: Google's documented trailing-slash handling. Confidence: high · Verified: Google Search Central Blog: To slash or not to slash Evidence for this claim Under URI resolution rules, a trailing slash changes path-base semantics; server behavior still determines the HTTP resource returned. Scope: URI reference resolution, distinct from search-engine canonical choice. Confidence: high · Verified: IETF RFC 3986: Reference resolutionTL;DR —
example.comandexample.com/are identical — the root domain is the only universal rule. Everywhere else/pageand/page/are distinct URLs, so both-live-and-unconsolidated means duplicate URLs. It doesn’t matter which format you pick; enforce one with a 301 redirect (the strong canonicalization signal — trailing slash is just one of ~40), backed by a canonical tag when a redirect isn’t feasible, plus consistent internal links and sitemap entries. Mind the file-path gotcha (page.html/is a distinct, server-dependent path), the REST API quirk (frameworks like Flask can treat/resourceand/resource/as different routes), double slashes (legal but can confuse crawlers), and redirect chains stacking with HTTPS/www hops. My standing advice holds: unless it’s causing a problem, don’t force a change.
What a trailing slash is (and where it came from)
A trailing slash is the forward slash at the end of a URL. As I put it in my Ahrefs trailing slash guide, “A trailing slash is a forward slash (”/”) placed at the end of a URL such as domain.com/ or domain.com/page/.”
The slash used to mean something specific. In the past, a folder would have a
trailing slash and a file would be without the trailing slash — the slash was
the server’s way of saying “this is a directory, a container of other things,” as
opposed to a single file like index.html. That distinction is largely historical
now: these days, URLs in most systems aren’t pointing to files. The URL is a
record stored in a database. Your CMS routes /blog/trailing-slash/ to a
database row, not to a folder on a hard drive, so the directory-vs-file semantics
have mostly dissolved into a formatting convention.
But the convention died while the underlying server behavior that produced it did not — which is where the gotcha below comes from.
The one universal rule: the root-domain exception
Here’s the single rule that’s true everywhere: the trailing slash on the bare
root domain is irrelevant. example.com and example.com/ are the same URL.
This isn’t an SEO nicety; it’s how HTTP works. A request for a homepage is
technically a request for / — the slash after the hostname is always there,
even when your browser hides it in the address bar. John Mueller has framed this
as the root’s trailing slash being implicitly present and implied for
canonicalization, so https://example.com is functionally https://example.com/
for Google’s purposes. There’s nothing to redirect at the root because there’s no
second URL — they’re one and the same resource. My own plain-language version of
the same rule: domain.com = domain.com/ — “These URLs are treated exactly
the same and it doesn’t matter which version you use.”
Everywhere else, that equivalence evaporates.
Everywhere else, it’s genuinely a different URL
The moment there’s a path after the domain, the slash is a real part of the URL.
As I wrote in the guide: for every case besides the trailing slash directly
after the root domain, a trailing slash will be treated as a separate URL. So
example.com/shoes and example.com/shoes/ are two distinct addresses.
If both load the same content and neither consolidates to the other, you’ve manufactured a duplicate-URL situation — the exact kind of thing the canonicalization sibling in this cluster exists to sort out. In most real setups this isn’t catastrophic, because a self-referencing canonical tag or Google’s own duplicate handling usually picks a preferred version. But “usually” isn’t “always,” and leaving it to chance means you’re relying on Google to guess correctly instead of telling it.
The gotcha that survived: don’t slash a real file
The file-vs-directory meaning faded, but the mechanical behavior didn’t.
In most cases, if you add a trailing slash to a file such as .html, .php, .js,
.css, .pdf, .jpg, etc., it won’t load the file. Mueller’s illustrative version
of this is https://www.google.com/humans.txt versus
https://www.google.com/humans.txt/ — appending a slash to an actual file path
produces a different URL that typically won’t resolve to the file (it 404s or is
otherwise mishandled). So while “add a trailing slash everywhere” sounds like a
tidy rule, it breaks on any URL that ends in a real filename — which is exactly
why the server-config rules below have to be file-aware.
REST APIs are a different story
Almost every trailing-slash article assumes a CMS front-end, where /page and
/page/ serve the same content and the only question is which one to consolidate
to. That assumption breaks for REST APIs.
Many API frameworks treat /resource and /resource/ as genuinely distinct
routes with different behavior — not duplicate views of one thing. Flask is the
clearest documented example: define a route with a trailing slash and requesting
the no-slash version auto-redirects to the slash version; define it without a
trailing slash and requesting the slash version returns a 404 rather than
redirecting, unless you explicitly relax that with strict_slashes=False. Express,
Django REST Framework, and others have their own conventions and toggles. The point
for developer-adjacent readers: don’t assume your CMS’s slash-forgiveness applies
to your API layer. A headless setup can have a slash-tolerant front end sitting on
top of a slash-strict API, and the two failure modes look nothing alike — one is an
SEO duplicate-content story, the other is a hard 404 in your app.
Pick a format and enforce it — redirect first, canonical as backup
The honest answer to “slash or no slash?” is that it doesn’t matter which you pick. Whether you choose to use a trailing slash or not is more of a personal preference than anything. Google’s reps have said the same thing for years: the best solution is to be consistent and only use one version of a URL — link to that version, redirect to it, use it in sitemaps, use it for rel-canonical. “Consistent” is the operative word. Every canonicalization signal should agree:
- Internal links all use the chosen format.
- Sitemap lists only the chosen version.
- Canonical tags point at the chosen version.
- Redirects send the other version to the chosen one.
On which signal does the heavy lifting: a redirect is far stronger than a bare canonical tag. Trailing slash is just one of the many canonicalization signals Google weighs — Gary Illyes has put the count at over twenty, and by 2025 Google was talking about roughly forty (I walk through the full list in my canonicalization guide). Crucially, Illyes said a “301 redirect, or any sort of redirect actually, should be much higher weight when it comes to canonicalization than whether the page is on an http URL or https.” And Google is explicit that a canonical tag is a hint, not a rule — it “may choose a different page as canonical than you do.” So: redirect when you can; fall back to canonical only when you genuinely can’t (shared hosting with no server-config access, a CDN/edge setup that doesn’t support rewrites, or a legacy system where both versions must stay independently reachable).
Enforcing it in server config
The single most important implementation detail — and the thing most copy-paste
snippets get wrong — is that your rule has to be file-aware and directory-aware,
so it doesn’t try to strip the slash off a real directory or bolt one onto a real
file. My Apache rules use !-d (not a directory) and !-f (not a file) guards for
exactly that reason; the Nginx and IIS equivalents below carry the same logic. Full
copy-pasteable snippets for both directions on all three servers are in the
Scripts tab.
The other detail that’s easy to miss: a “remove the trailing slash” rule also has to
exclude the bare root. A request for your homepage is a request for / — strip
the slash there with a naive ^(.*)/$ pattern and the rule matches its own output,
redirecting / to /. That’s a same-URL 301, and depending on the server and
client it can loop instead of resolving. Since the root is the one place a slash
never matters anyway (see above), just carve it out of the rule explicitly rather
than relying on it happening to fail to match. And whatever engine you’re on, let
the substitution pass the original query string through unchanged — don’t drop
?utm_source=... or similar off the back of a slash redirect.
- Apache —
.htaccesswithmod_rewrite, using the!-d/!-fguards. - Nginx — a
rewrite ... permanentrule (orreturn 301), withtry_fileshandling real files/directories. - IIS — the URL Rewrite module, expressed as
<rule>blocks inweb.config.
Whichever server you’re on, do both directions of the decision in one rule so you’re not stacking hops (more on that under pitfalls).
CMS and platform defaults
Most people never touch server config because their platform already picks a format — you just want to know what it picked and standardize on it.
- WordPress adds a trailing slash by default with the standard “Post name”
permalink structure. You control it under Settings > Permalinks: as I note in
the guide, “
/%postname%/would add the trailing slash to URLs/%postname%would remove the trailing slash from URLs.” Change the custom structure and it retroactively changes your site-wide format — which is a URL change, with all the usual risk. - Other platforms vary. Shopify, Squarespace, Wix, and various static-site generators each have their own default and their own (sometimes limited) ability to change it. Don’t assume — check yours, then make your internal links, canonicals, and sitemap match whatever the platform actually emits.
Common pitfalls
A few failure modes that show up alongside trailing-slash inconsistency:
- The self-referencing-canonical trap. The generic advice that “every page should have a self-referencing canonical” gets SEOs in trouble when a developer makes both the slash and non-slash version self-canonical — each pointing at itself — instead of having one redirect or canonicalize to the other. Two pages each declaring “I’m the canonical” defeats the entire purpose. One of them needs to point at the other.
- Double slashes (
//). A buggy redirect rule that adds a slash without checking whether one already exists can produceexample.com//page/. Per RFC 3986 that’s technically legal — Illyes put it as “From a puritan perspective, that’s not an issue… the forward slash is a separator and is OK to appear in the URL path as many times as you like.” But he immediately added: “From a usability perspective it’s probably not the greatest idea, and it may also confuse some crawlers.” Avoid them. - Redirect chains. Trailing-slash redirects love to stack with your other canonicalization redirects — HTTP→HTTPS, non-www→www (or the reverse), and casing. A single request can end up hopping through three or four 301s before it lands. Each hop costs a little crawl efficiency and adds latency. Resolve all the canonicalization dimensions (protocol, host, slash, case) in one redirect where your server config allows it, and update internal links to point at the final URL so you’re not relying on the redirect at all.
- Cross-engine strictness. Independent testing has found Bing tends to crawl and index only one version of a slash/no-slash pair, while Google will crawl both and filter one — so slash inconsistency can surface differently across engines. Treat that as a reason to be tidy, not as an official Bing rule.
A few myths worth killing
- “There’s a right slash format for SEO.” There isn’t — except at the root, where it doesn’t matter at all. Consistency beats choice.
- “A trailing slash always means directory today.” Historical. Most URLs are database records now, though servers can still be configured to behave the old way (which is why file paths still misbehave when you slash them).
- “Inconsistency automatically halves your rankings/link equity.” Unsourced. The accurate version is that duplicate URLs split signals across two addresses instead of consolidating onto one — a real effect, but not a literal 50/50 law.
- “A canonical tag is enough; you don’t need a redirect.” Canonical is a hint Google can override; a 301 is a much stronger signal. Redirect when you can.
Should you change your existing URLs? Usually not.
If your site already works and you’re just tidying for tidiness’ sake, my answer is the same one I give for URL changes generally: “There’s always a risk with changes, so unless your setup is causing issues I wouldn’t try to force a change to your URLs.” Changing your slash format site-wide is a full URL migration — every URL 301s, internal links need updating, and there’s always some reprocessing cost and risk of botched redirects. That’s worth it if you have a genuine problem (both versions indexed and fragmenting a page, a slash-strict API 404ing users, a messy chain of redirects). It’s not worth it to make your URLs “look right.” Set new sites up consistently from day one; leave working sites alone.
This topic sits right next to its siblings in the website-structure cluster — url-structure (its parent, where trailing slash is one section of the broader picture), canonicalization (the machinery that resolves duplicate slash variants), site-architecture, and website-structure. They’ll link up automatically.
AI summary
A condensed take on the Advanced version:
- A trailing slash is the
/at the end of a URL (example.com/page/vsexample.com/page). Historically it meant “directory, not file”; most URLs are database records now, so that meaning has faded. - Root-domain exception is the one universal rule:
example.com=example.com/, always — the slash after a hostname is implicitly there and implied for canonicalization. Nothing to redirect at the root. - Everywhere else,
/page≠/page/— two distinct URLs. Both live and unconsolidated = duplicate URLs splitting signals. - The surviving gotcha: adding a slash to a real file path (
page.html/,logo.png/) won’t load the file — it’s a different, usually broken, URL. - REST APIs differ from CMSs: many frameworks (e.g. Flask, via
strict_slashes) treat/resourceand/resource/as genuinely different routes — one redirects, the reverse 404s. Don’t assume CMS slash-forgiveness applies to your API layer. - It doesn’t matter which format you pick — be consistent. Make internal links, sitemap, canonical, and redirects all agree.
- Redirect first, canonical as backup. Trailing slash is one of ~40 canonicalization signals; a 301 outweighs a bare canonical (Illyes), and canonical is “a hint, not a rule” (Google).
- Enforce in server config file-awarely: Apache (
mod_rewritewith!-d/!-fguards), Nginx (rewrite/try_files), IIS (URL Rewriteweb.config) — both directions in the Scripts tab. - CMS defaults: WordPress adds a trailing slash by default (
/%postname%/); change under Settings > Permalinks. Other platforms vary — check yours. - Pitfalls: self-referencing canonicals on both variants; double slashes (legal per RFC 3986 but “may confuse some crawlers”); redirect chains stacking with HTTPS/www/case; Bing tends to index only one variant.
- Should you change existing URLs? Usually no — “unless your setup is causing issues I wouldn’t try to force a change to your URLs.”
Official documentation
Primary-source documentation from the search engines. Google never shipped a dedicated help-center page on trailing slash the way it did for, say, hreflang, so the relevant guidance lives in its canonicalization and URL-structure docs plus the 2010 blog post.
- To slash or not to slash — the original Google post on the topic (Maile Ohye, 2010, still live and reconfirmed 2026-07-18): Google treats slash and non-slash URLs as separate, either can be the preferred version, and — its own words — the root can’t be redirected “even if you’re Chuck Norris.”
- What is URL canonicalization — where trailing slash sits today: duplicate-URL handling, the canonicalization signals, and the “a hint, not a rule” framing for canonical tags.
- How to specify a canonical URL — redirects vs. canonical tags vs. sitemap inclusion and their relative strengths (redirect = strong; sitemap = weak).
- URL structure best practices — general URL guidance (IETF STD 66, encoding, hyphens, casing); no trailing-slash-specific section, but the neighboring rules apply.
Bing / Microsoft
- Better than canonical; URL Normalization — Bing Webmaster Tools’ way to collapse URL variants with a proactive normalization signal rather than relying on
rel=canonicalalone. - Bing Webmaster Guidelines — general URL-cleanliness guidance (short, keyword-rich, avoid session variables); doesn’t address trailing slash specifically.
Quotes from the source
On-the-record statements. Where a source page resists automated checking (some are JavaScript-rendered or block direct fetching), the passage is relayed through verbatim secondary coverage and flagged below — confirm against the live page before treating as final.
Gary Illyes, Google — double slashes (Search Engine Journal, verbatim)
- “From a puritan perspective, that’s not an issue. If you look at RFC 3986, section 3, the forward slash is a separator and is OK to appear in the URL path as many times as you like, even repeatedly.” Jump to quote
- “From a usability perspective it’s probably not the greatest idea, and it may also confuse some crawlers.” Jump to quote
Gary Illyes, Google — canonicalization signal weighting (Search Engine Journal, verbatim)
- “We employ, I think, over twenty signals, we use over twenty signals, to decide which page to pick as canonical from a dupe cluster.” Jump to quote
- “301 redirect, or any sort of redirect actually, should be much higher weight when it comes to canonicalization than whether the page is on an http URL or https.” Jump to quote
Google — canonical is a hint (Search Central docs, verbatim)
- “Google may choose a different page as canonical than you do, for various reasons. That is, indicating a canonical preference is a hint, not a rule.” Jump to quote
Maile Ohye, Google — the original 2010 post (Search Central Blog, verbatim, reconfirmed live 2026-07-18)
-
“Rest assured that for your root URL specifically, https://example.com is equivalent to https://example.com/ and can’t be redirected even if you’re Chuck Norris.” Jump to quote
-
“Google treats each URL above separately (and equally) regardless of whether it’s a file or a directory, or it contains a trailing slash or it doesn’t contain a trailing slash.” Jump to quote
This is the source the brief flagged as needs-review because earlier fetch attempts only returned the nav shell. Refetched directly this pass — the post is still live at its original URL, dated 2010, byline Maile Ohye — and both lines above are pulled verbatim from the current page.
John Mueller, Google — the root-domain exception (his own “randoms” blog, verbatim, reconfirmed live 2026-07-18)
-
“The slash after a hostname or domain name is irrelevant, you can use it or not when referring to the URL, it ends up being the same thing. However, a slash anywhere else is a significant part of the URL and will change the URL if it’s there or not.” Jump to quote
johnmu.com blocked direct fetch when the brief was researched; it’s reachable now, and this is the exact wording of the 2017 post (his write-up of an earlier Google+ answer), including his own framing that this “is not SEO-specific, but just how websites work” — grounded in HTTP request syntax, not a search-engine rule.
Patrick Stox (me) — from my Ahrefs trailing slash guide (my own words)
- “A trailing slash is a forward slash (”/”) placed at the end of a URL such as domain.com/ or domain.com/page/.” Source
- “These URLs are treated exactly the same and it doesn’t matter which version you
use.” (on
domain.com=domain.com/) - “In most cases, if you add a trailing slash to a file such as .html, .php, .js, .css, .pdf, .jpg, etc., it won’t load the file.”
- “Whether you choose to use a trailing slash or not is more of a personal preference than anything.”
- “There’s always a risk with changes, so unless your setup is causing issues I wouldn’t try to force a change to your URLs.”
Trailing-slash audit — checklist
A quick pass to confirm one format is chosen and every signal agrees:
- Decided on one format — slash or no slash — for the whole site (root domain excepted, where it doesn’t matter).
- The other version 301-redirects to your chosen version, site-wide.
- The redirect rule is file-aware and directory-aware — it doesn’t strip
the slash off real directories or add one to real files (
.pdf,.jpg,.css, etc.). - Internal links all use the chosen format (no mix of slashed and unslashed links to the same pages).
- XML sitemap lists only the chosen version.
- Canonical tags point at the chosen version — and you’re not letting both the slash and non-slash variant self-canonicalize.
- No redirect chains — the slash redirect is combined with HTTPS/www/case redirects into a single hop, and internal links point at the final URL.
- No double slashes (
//) generated by a buggy rewrite rule. - CMS default checked — you know whether your platform emits a trailing
slash by default (WordPress does with
/%postname%/) and your signals match it. - API layer checked separately — if you have a REST API, confirmed its
slash handling (
strict_slashesor equivalent) rather than assuming CMS behavior. - GSC spot-check — no unexpected “Duplicate, Google chose different canonical than user” from slash variants; both versions aren’t both indexed.
Trailing slash — cheat sheet
Does the slash matter here?
| Location | /x vs /x/ | Verdict |
|---|---|---|
Bare root domain (example.com) | Identical | Doesn’t matter — pick either |
Any path (example.com/page) | Different URLs | Matters — pick one, enforce it |
A real file (page.html, logo.png) | Slashed version usually won’t load | Never add a slash |
A REST API route (/resource) | Often distinct routes | Check the framework — may redirect or 404 |
Enforce with the right tool
| You want to… | Use | Not |
|---|---|---|
| Force one slash format site-wide | 301 redirect (server config) | a canonical tag alone |
| Consolidate when you can’t redirect | rel="canonical" (fallback) | nothing / hoping Google guesses |
| Point at the preferred version everywhere | Consistent internal links + sitemap | a mix of both formats |
Signal strength (why redirect first)
- 301 redirect — strong; outweighs the HTTPS signal (Illyes).
rel="canonical"— a hint, not a rule; Google can override it.- Trailing slash is one of ~40 canonicalization signals — not special, just one more thing that should agree.
Fast facts
- Root domain:
example.com=example.com/. Always. - WordPress default: trailing slash on (
/%postname%/); toggle in Settings > Permalinks. - Double slashes (
//): legal per RFC 3986, but “may confuse some crawlers” — avoid. - Server rules must be file/directory-aware (
!-f/!-don Apache). - Don’t change a working site’s format just to tidy it: “unless your setup is causing issues I wouldn’t try to force a change to your URLs.”
Enforce a trailing-slash rule — server config
Copy-pasteable rules for both directions on all three major servers. The
non-negotiable detail in every one of these: it must exclude real files and real
directories, so it doesn’t try to strip the slash off a folder or bolt one onto
style.css. Pick one direction; don’t apply both. And ideally fold these into
your existing HTTPS/www redirect so you resolve everything in a single hop.
Apache (.htaccess, mod_rewrite)
Remove the trailing slash (canonical = no slash):
RewriteEngine On
# Don't touch the root: "/" is the homepage, and stripping its slash
# with the pattern below would redirect "/" to "/" — a same-URL loop.
RewriteCond %{REQUEST_URI} !^/$
# Don't touch real directories (they legitimately end in /)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]Add a trailing slash (canonical = with slash):
RewriteEngine On
# Don't touch real files (.jpg, .css, .pdf, etc.)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]The !-d guard on the “remove” rule keeps it from breaking directory requests; the
!-f guard on the “add” rule keeps it from slash-suffixing real files. That
file/directory awareness is the whole trick — carry the same logic into the Nginx
and IIS versions. The root exclusion on the “remove” rule matters for a different
reason: without it, the pattern matches the homepage’s own / and rewrites it to
/ — an identical-URL 301 that some clients treat as a redirect loop rather than a
no-op. (mod_rewrite passes the original query string through by default when the
target has none of its own, so you don’t need QSA here — just don’t add a literal
? to the substitution or you’ll strip it.)
Nginx (rewrite / try_files)
Remove the trailing slash:
# Strip a trailing slash on anything that isn't a real directory.
location / {
# If the request maps to a real file or directory, serve it as-is.
if (-e $request_filename) {
break;
}
rewrite ^/(.*)/$ /$1 permanent;
try_files $uri $uri/ /index.php?$query_string;
}Add a trailing slash:
location / {
# Only add a slash when the path has no file extension (i.e. not a real file).
if ($uri ~ ^(.*[^/])$) {
rewrite ^(.*[^/])$ $1/ permanent;
}
try_files $uri $uri/ /index.php?$query_string;
}Nginx doesn’t have Apache’s !-f/!-d operators, so -e $request_filename (the
path exists on disk) and an extension check stand in for the same “leave real
files/directories alone” guard. That -e check also happens to keep the root safe
from the same self-redirect issue called out in the Apache section — root maps to a
directory that exists on disk, so it breaks out before the rewrite runs — but
don’t rely on that as documentation; test the root explicitly after deploying.
Adjust the try_files fallback to match your app (the /index.php line assumes
PHP; swap for your backend).
IIS (URL Rewrite module, web.config)
Remove the trailing slash:
<rewrite>
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>Add a trailing slash:
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>IIS’s IsFile / IsDirectory conditions (negated) are the exact analog of
Apache’s !-f / !-d — same guard, different syntax. redirectType="Permanent"
issues the 301.
WordPress (no server config needed)
If you’re on WordPress you usually don’t touch any of the above — set the format in
Settings > Permalinks: /%postname%/ adds the trailing slash, /%postname%
removes it. Changing the custom structure rewrites your URLs site-wide, so treat it
as a URL migration (redirects, sitemap update), not a cosmetic tweak.
What not to do
The recurring ways trailing-slash handling goes wrong:
- Letting both variants self-canonicalize. Following “every page needs a
self-referencing canonical” too literally, so
/pagecanonicals to/pageand/page/canonicals to/page/. Both declare themselves the canonical, which consolidates nothing. One must redirect or canonicalize to the other. - A canonical tag instead of a redirect when a redirect is available. Canonical is a hint Google can override; a 301 is the strong signal. If you control the server, redirect — don’t settle for the weaker signal.
- A slash rule that isn’t file/directory-aware. Blindly appending a slash to
everything breaks
style.css→style.css/; blindly stripping it breaks real directory requests. Always guard with!-f/!-d(orIsFile/IsDirectoryon IIS,-e/extension checks on Nginx). - Stacking redirects. A separate hop each for HTTPS, www, and slash means a single request chains through three or four 301s. Combine them into one rule, and update internal links so they hit the final URL directly.
- Buggy rewrites that emit double slashes. A rule that adds
/without checking whether one’s already there yieldsexample.com//page/. Legal per RFC 3986, but “may confuse some crawlers.” - Adding a slash to a real file.
/document.pdf/,/logo.png/— different URL, won’t load the file. The historical directory-vs-file behavior still bites here. - Assuming your API behaves like your CMS. A slash-tolerant front end can sit on a slash-strict API that 404s the “wrong” version. Check the framework’s slash handling separately.
- Changing a working site’s format for tidiness. It’s a full URL migration with real risk. Unless something’s actually broken, leave it — set new sites up consistently from the start instead.
Resources worth your time
My related writing
- Trailing Slash: To Use or Not to Use? — my original guide on this exact topic: the root-domain exception, the file-path gotcha, WordPress permalinks, and the Apache add/remove snippets. This article is its deep-dive successor.
- Google Uses ~40 Canonicalization Signals — why trailing slash is just one of many signals, and why a redirect outweighs a bare canonical tag.
- URL Parameters: A Complete Guide for SEOs — the sibling URL-hygiene topic (the other big manufacturer of duplicate URLs).
- Redirects for SEO: A Simple (But Complete) Guide — the mechanics of the 301s you use to enforce slash consistency, and how to avoid redirect chains.
- The Beginner’s Guide to Technical SEO — where URL hygiene fits the bigger picture.
My speaking
- A Crash Course in Technical SEO (SlideShare, Beer & SEO Meetup) — URL structure and canonicalization in context.
- Canonicalization for SEO — BrightonSEO, April 2023 (SlideShare) — the clustering/selection model that decides which slash variant wins.
From around the industry
- To slash or not to slash (Google Search Central Blog, Maile Ohye, 2010) — the foundational Google post: different URLs, choose either, consolidate.
- Google Answers If Double Slash In URL Has SEO Impact (Search Engine Journal) — Illyes on
//: legal per RFC 3986 but “may confuse some crawlers.” - How Google Chooses Canonical Page (Search Engine Journal) — Illyes on the 20+ canonicalization signals and redirect-outweighs-HTTPS weighting.
- Trailing Slashes and SEO: Quick Tips and Gotchas (Positional) — a clean current write-up, strong on updating internal links to avoid redirect chains.
- Better than canonical; URL Normalization (Bing Webmaster Blog) — Bing’s proactive normalization approach to collapsing URL variants.
- Remove HTML Extension And Trailing Slash In Nginx Config (Sean C Davis) — a practical Nginx
rewrite/try_filesreference. - IIS: Add/Remove Trailing Slash (RewriteGuide) — IIS URL Rewrite module rules for both directions.
Common trailing-slash failures
Both versions return 200
Symptom: /page and /page/ load the same content without redirecting.
Likely cause: The application routes both forms but the edge or server does not
enforce a preferred format. Fix: Pick the existing dominant format, add a
one-hop permanent redirect from the alternate, and align canonicals, internal links,
and sitemaps.
The slash rule creates a redirect chain
Symptom: A request changes HTTP to HTTPS, then hostname, then slash in separate hops. Likely cause: Independent normalization rules run sequentially. Fix: Combine them so every alternate goes directly to the final HTTPS, preferred-host, preferred-slash URL.
File URLs or API routes start failing
Symptom: Assets, filenames, or API endpoints return errors after global slash normalization. Likely cause: A directory-style rule was applied to routes with different semantics. Fix: Exclude real files and API namespaces, then test those route classes separately before re-enabling the rule.
Patrick's relevant free tools
- Redirect Map Builder — Plan a site migration: paste old and new URLs and get a suggested 301 map — each row scored into a confidence tier with a plain reason, an override dropdown, a first-class unmatched bucket, a 410 kill-list, chain-flattening so the map never creates the chains it prevents, and platform-accurate exports for Apache, nginx, and Cloudflare. Optional metadata-only content matching closes the last-mile gaps. Structural matching runs entirely in your browser.
Tools for slash normalization
- Redirect Chain Mapper — show every normalization hop and identify whether HTTPS, hostname, and slash rules can be collapsed.
- Redirect Checker — spot-check a short list of slash and no-slash pairs after deployment.
- Canonicalization Checker — compare redirect, canonical, and indexability signals when both URL forms have been exposed.
- A full-site crawler — find internal links and sitemap entries that still emit the non-preferred form; redirect checks alone do not fix those sources.
Verify a representative URL pair
Test to run: Request both /path and /path/ with the Redirect Chain
Mapper. Expected result: The preferred form loads
normally and the alternate permanently redirects to it in one hop.
Failure interpretation: The normalization rule is missing, reversed, or stacked with other
redirect rules. Monitoring window: Immediate after deployment.
Rollback trigger: The preferred URL loops, redirects away from the intended page, or stops
returning a successful response.
Verify route-class exclusions
Test to run: Check samples of HTML pages, real files, API endpoints, query-string URLs, and the root domain. Expected result: Page routes normalize consistently, while excluded route classes retain their required behavior and the root resolves without a loop. Failure interpretation: A global rewrite is matching more paths than intended. Monitoring window: Immediate, in every environment where routing differs. Rollback trigger: Assets or APIs fail, or any URL enters a redirect loop.
Test yourself: Trailing Slash
Five quick questions on how the trailing slash behaves and how to enforce one format. Pick an answer for each, then check.
Trailing Slash
A trailing slash is the forward slash (/) at the end of a URL — example.com/page/ versus example.com/page. Except at the bare root domain, the two versions are different URLs to search engines, so you pick one format and enforce it.
Related: URL Structure, Canonicalization, 301 redirect
Trailing Slash
A trailing slash is a forward slash (/) placed at the end of a URL, such as example.com/ or example.com/page/. Historically the slash signaled that a URL pointed at a directory (a container of other resources) rather than a single file. Most modern URLs aren’t literal files on disk anymore — they’re records served from a database or application router — so that file-vs-directory meaning has mostly faded.
What hasn’t faded is the mechanical consequence: search engines treat example.com/page and example.com/page/ as two different URLs. There is exactly one exception — the bare root domain, where example.com and example.com/ are identical and it doesn’t matter which you use.
Because the two versions are distinct URLs everywhere else, having the same content reachable on both can create duplicate URLs that split signals. The fix isn’t to pick the “correct” slash — there is no universally correct one — it’s to choose a single format and enforce it consistently with 301 redirects, canonical tags, internal links, and sitemap entries all pointing the same direction. Adding a slash to an actual file path (/style.css/, /page.pdf/) generally won’t load the file, and REST API frameworks often treat /resource and /resource/ as genuinely different routes — two edge cases that trip people up.
Related: URL Structure, Canonicalization, 301 redirect
Build-time retrieval analysis plus live signals for this exact article. The automatic chunk report includes a deterministic readiness score and is ready without a model download.
Search Console
sampleGA4 traffic (28d)
sampleCloudflare traffic (7d)
sampledCrUX field data (28d, phone)
sampleGoogle NLP entities
localChangelog
Updated Jul 18, 2026.
Editorial summary and recorded change details.Summary
Fixed a real redirect-loop bug in the copy-pasteable Apache trailing-slash-removal snippet (it could self-redirect the homepage), added the same root-exclusion and query-preservation guidance to the server-config prose and Nginx notes, and upgraded two previously unverified/paraphrased quotes (Google's 2010 blog post and John Mueller's root-domain post) to direct verbatim quotes after both sources loaded live on a fresh fetch this pass.
Change details
-
Added a `RewriteCond %{REQUEST_URI} !^/$` guard to the Apache 'remove trailing slash' snippet and explained why: without it, the rule redirects the homepage's `/` to `/`, a same-URL 301 that can loop instead of resolving.
-
Added root-exclusion and query-string-preservation guidance to the 'Enforcing it in server config' section and a matching note on why the Nginx snippet is already safe on the root.
-
Reconfirmed Google's 2010 'To slash or not to slash' post is still live at its original URL (it had returned only a nav shell on the prior research pass) and added its verbatim root-exception line to the Quotes tab and Official Docs description.
-
Reconfirmed John Mueller's johnmu.com root-domain post is now reachable (it 403'd on the prior research pass) and upgraded the Quotes tab from a paraphrase to the verbatim quote.
Full comparison unavailable — no prior snapshot was archived for this revision.