Skip to content

thedaviddias/Front-End-Checklist / skills/trailing-slash

trailing-slash

Verified

Use when applies to all static and dynamic websites. Use when auditing a site for duplicate content, setting up a new site, or after migrating platforms that changed URL conventions.

FileKindSize
SKILL.mdskill md2.1 KB
references/rule.mdmarkdown3.7 KB

references/rule.md

View on GitHub
# Use trailing slashes consistently

> Checks for consistent trailing slash usage across all URLs to avoid duplicate content and canonicalization issues.

**Priority:** medium · **Difficulty:** beginner · **Time:** 10 min

---
A trailing slash makes `/page/` different from `/page` at the HTTP level. Without consistent handling, you have two URLs serving the same content — a classic duplicate content problem.
## Code Examples

#

## Option A: Prefer no trailing slash (common for frameworks like Next.js)

```
preferred URL → 200 OK
alternate slash variant → 301 → preferred URL
```

### Option B: Prefer trailing slash (common for WordPress, Apache-based sites)

```
preferred slash URL → 200 OK
alternate no-slash variant → 301 → preferred slash URL
```

## Why It Matters

Inconsistent trailing slashes create duplicate content — Google sees `/page` and `/page/` as two separate URLs competing for the same ranking, splitting PageRank between them.

## The Problem

| URL | HTTP Status | Issue |
|-----|-------------|-------|
| `/about` | 200 OK | Content served |
| `/about/` | 200 OK | Same content — DUPLICATE |

Both versions appear in Google's index as separate pages, splitting link equity and creating canonicalization ambiguity.

## Implementation

### Next.js

```js
// next.config.js
module.exports = {
  trailingSlash: false,   // 'true' for trailing slash preference
}
```

### Nginx

```nginx
# Redirect trailing slash to no-slash
rewrite ^/(.*)/$ /$1 permanent;
```

### Apache

```apache
# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
```

## Canonical Tags

Regardless of server redirects, add canonical tags pointing to the preferred version:

```html
<!-- On https://example.com/about (preferred) -->
<link rel="canonical" href="https://example.com/about">

<!-- If the trailing slash version also serves: -->
<!-- On https://example.com/about/ -->
<link rel="canonical" href="https://example.com/about">
```

## ❌ Common Mistakes

```html
<!-- Canonical points to trailing slash but all internal links omit it -->
<link rel="canonical" href="https://example.com/about/">
<a href="/about">About</a>   <!-- Creates a redirect per navigation -->

<!-- Sitemap mixes conventions -->
<loc>https://example.com/about</loc>
<loc>https://example.com/contact/</loc>
```

## Checking Consistency

```
curl -I https://example.com/about
curl -I https://example.com/about/
```

One must return `HTTP/1.1 301` with a `Location:` header pointing to the preferred URL.

## Exceptions

- Staging, utility, login, account, or internal search pages may intentionally use different crawl or index signals if they are not meant to rank.
- Temporary migration states can produce noisy intermediate signals; flag the live production URL pattern, not one-off transition artifacts.
- When redirects, canonicals, robots directives, or indexability signals conflict, fix the strongest final signal first instead of reporting every downstream symptom as a separate blocker.

## Standards

- Use these references as the standard for the final search-facing HTML, metadata, and crawl behavior.
- Check the implementation against Google: Trailing slashes on URLs before treating the rule as satisfied.
- Check the implementation against Google: Consolidate duplicate URLs before treating the rule as satisfied.

## Verification

### Automated Checks

- Inspect rendered HTML and HTTP headers to confirm the expected metadata or crawlability signal is present.
- Test the affected URL with Google Search Console or equivalent tooling where relevant.
- Re-crawl a representative page set after deployment.

### Manual Checks

- Confirm the change does not create conflicting canonical-url, robots, or structured-data signals.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall