/ โ† Redirect Fixes / Trailing Slash
In this guide
  1. Why the slash creates two pages
  2. Finding out what your site does now
  3. Choosing with or without
  4. Where the slash behaviour comes from
  5. Rules that handle files and folders correctly
  6. The fix, step by step
  7. Edge cases worth checking
  8. Keeping it consistent
  9. Questions and answers

Why the slash creates two pages

A URL path is just a string. Nothing in the HTTP rules says that a path ending in a slash and the same path without one must lead to the same thing. Historically the slash meant "this is a folder" and no slash meant "this is a file", which is why a traditional server asked for /team, where team is a folder, answers with a redirect to /team/ and then serves the index.html inside it. Modern sites rarely map URLs to real folders, so the router in the CMS or framework decides what each form does, and different routers decide differently.

There are three states a URL can be in:

StateWhat the checker seesVerdict
Both forms return 200/pricing 200 and /pricing/ 200Duplicate pages. Needs a redirect or at least a consistent canonical tag.
One form redirects to the other/pricing/ 301 to /pricing, which returns 200Healthy, as long as it is one hop and your links use the final form.
One form returns 404/pricing 200 and /pricing/ 404Not a duplicate, but anyone who types or links the other form hits an error. A redirect is kinder.

Google treats the two forms as separate URLs, and it will usually pick one as canonical by itself using the signals it has: redirects, canonical tags, internal links and the sitemap. When those signals agree, a stray duplicate causes very little trouble. When they disagree, for example the menu links without a slash, the sitemap lists slashes, and both forms return 200, you leave the choice to Google and may see the "wrong" form in results or reports split across two addresses.

๐Ÿ’ก The site root is the one exception you never need to handle. https://example.com and https://example.com/ are the same request: a browser always sends the path / for the bare domain. Only paths below the root can differ.

Finding out what your site does now

Start with evidence rather than assumptions, because different parts of one site often behave differently. Blog posts may be handled by the CMS, product pages by a shop plugin and landing pages by static files, each with its own slash habit.

Pick ten to twenty URLs covering each kind of page: the homepage, a top-level page, a nested page, a blog post, a category or tag page, a product, a search results page, a PDF and a real folder if you have one. For each, request both forms without following redirects:

for u in /pricing /pricing/ /blog/spring-menu /blog/spring-menu/ /files/menu.pdf /files/menu.pdf/; do
  printf "%-28s " "$u"
  curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" "https://www.example.co.uk$u"
done

Typical output from a site that has drifted looks like this:

/pricing                     200
/pricing/                    200
/blog/spring-menu            301 https://www.example.co.uk/blog/spring-menu/
/blog/spring-menu/           200
/files/menu.pdf              200
/files/menu.pdf/             200

That tells you three things: the blog already has a with-slash convention, ordinary pages have none, and something is happily serving a PDF at an address ending in a slash, which usually means a catch-all route is swallowing it. Now run the same URLs through the Redirect Checker from the http and non-www starting points as well, because the slash rule usually interacts with the host rules. Finally, look at Search Console's page indexing report and the URL Inspection tool for a couple of pages to see which form Google has chosen as canonical. That is useful evidence when you choose.

Choosing with or without

Neither form ranks better. The deciding factors are practical: which form your existing links use, which form your platform produces naturally, and how much work each choice creates.

Once you have chosen, write the decision down in one sentence, for example "All page URLs end in a slash except files with an extension", and make every later change follow it.

Where the slash behaviour comes from

WordPress

The permalink structure under Settings, Permalinks controls it. If the structure ends in /, WordPress generates slash links and its built-in canonical redirect sends the no-slash form to the slash form; remove the final slash and it does the reverse. Problems appear when a redirect plugin or an .htaccess rule enforces the opposite of the permalink setting, which produces a loop, or when pages created by a shop or membership plugin use their own routes. Change the permalink structure only as a deliberate project, because it changes every URL on the site.

Apache

The mod_dir module's DirectorySlash setting, on by default, redirects a request for a real folder without its slash to the slash form. That is correct for real folders and is why switching it off is rarely wise: with it off, relative links inside folder index pages break and directory listings can leak. Rules in .htaccess can add or remove slashes for everything else.

nginx

A try_files $uri $uri/ ... line makes nginx treat a request that matches a folder as a directory request, and nginx then issues its own 301 to add the slash. Behind a load balancer or proxy that redirect can point to the wrong scheme or port, such as http://www.example.co.uk:8080/team/, which is a classic source of odd extra hops. Setting absolute_redirect off; makes nginx send a relative Location instead, and port_in_redirect off; stops it adding the internal port.

Frameworks and static hosts

Next.js, Nuxt, Astro, Gatsby, Hugo, Eleventy and similar tools each have an option or a convention for this; Next.js, for example, redirects the non-preferred form with a 308 by default. Static hosts such as GitHub Pages, Netlify and Cloudflare Pages also normalise URLs according to how the files are laid out, and some offer a "pretty URLs" style setting. Check the documentation for the exact version you run and let one of these layers own the rule, not two.

Shopify and other hosted builders

On fully hosted platforms you usually cannot change the slash behaviour at all. Focus on the parts you do control: use the form the platform produces in every link you write, in campaigns and in any external listings.

Rules that handle files and folders correctly

The rule has to do three things: act only on paths that are not real files, leave real folders to the server's own behaviour, and send the visitor straight to the final HTTPS host in the same hop. Here are tested patterns for the two common choices.

Apache, removing the slash

RewriteEngine On
# leave real folders alone; mod_dir handles them
RewriteCond %{REQUEST_FILENAME} !-d
# only paths that end in a slash and are not the root
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^ https://www.example.co.uk%1 [R=301,L]

Apache, adding the slash

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# skip anything that looks like a file name with an extension
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{1,5}$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ https://www.example.co.uk%{REQUEST_URI}/ [R=301,L]

nginx, removing the slash

# inside the server block for the canonical host
location ~ ^(.+)/$ {
    if (!-d $request_filename) {
        return 301 $scheme://$host$1$is_args$args;
    }
    try_files $uri $uri/ /index.php?$args;
}

nginx, adding the slash

rewrite ^([^.?]*[^/])$ $1/ permanent;

The nginx add-slash rewrite only matches paths with no dot and no final slash, so /menu.pdf and /sitemap.xml are left alone. rewrite keeps the query string automatically. Place slash rules after your host and HTTPS handling or merge them into it, as the next section explains, and test with nginx -t or apachectl configtest before reloading.

โš ๏ธ Put the slash rule in only one place. If WordPress, a plugin, the framework or the CDN already enforces a form, adding a server rule for the opposite form creates a loop, and adding one for the same form just adds a hop.

The fix, step by step

Step 1

Test both forms of a sample of URLs

Choose ten to twenty addresses covering every kind of page on the site: top-level pages, nested pages, posts, categories, products, a PDF and any real folder. Request each one with and without the final slash using curl or the Redirect Checker and record the status code and redirect target for both. Note which sections return 200 twice, which already redirect, and which return 404, because different sections often come from different software.

Step 2

Choose the form your site already mostly uses

Count which form appears in the sitemap, the main menu and the internal links, and check which form Google shows as the canonical in URL Inspection for a few key pages. Pick that form unless your platform strongly prefers the other. Write the decision down as one sentence, including the exceptions, such as files with an extension and form or API endpoints that must not be redirected.

Step 3

Write one rule that skips files and existing folders

Add a single rule in the layer that should own it, whether that is the CMS setting, the framework option, the web server or the CDN. The rule must ignore paths with a file extension, leave real folders to the server, keep the query string, and use a 301 or 308. Remove any rule elsewhere that enforces a slash form, especially one that enforces the opposite form.

Step 4

Fold the slash rule into the host rules

Request http://example.co.uk/pricing and follow the chain. If the result is three hops, one for HTTPS, one for www and one for the slash, rewrite the rules so the first response already points at https://www.example.co.uk/pricing/ or whichever form you chose. On Apache that means building the full target in one RewriteRule; on nginx, one return 301 that includes the corrected path.

Step 5

Make links, canonicals and the sitemap match

Every internal link, menu item, canonical tag, hreflang tag, Open Graph URL and sitemap entry should use the chosen form exactly, so that nothing on your own site points at an address that redirects. Search the templates and content for the other form, update hard-coded links in page builders and footers, regenerate the sitemap, and update links in email signatures, ad campaigns and business listings where you can.

Step 6

Recheck chains and watch Search Console

Run the same sample through the Redirect Checker again from every starting variation: http, https, www, non-www, with and without the slash. Each should reach the final page in no more than one redirect. Then use URL Inspection on a few important pages, request indexing if you changed their form, and check the page indexing report over the following weeks for "Page with redirect" entries you did not expect.

Edge cases worth checking

Keeping it consistent

Slash drift usually returns through new content rather than through server changes. A few habits stop it:

Questions and answers

1. Does Google prefer URLs with or without a trailing slash?

No. Google has said it treats the two forms as different URLs but has no preference for either, so neither form ranks better. What matters is that each page has one form that your redirects, canonical tags, internal links and sitemap all agree on. If they point at different forms, Google has to choose for you and may pick the one you did not intend. Pick the form that matches your existing links and platform, then use it everywhere.

2. Is it a problem if both versions return a 200 status?

It is a mild problem rather than an emergency. Search engines usually work out that the pages are the same and pick one, especially if your canonical tag is consistent. But you leave that choice to them, links from other sites may be split between two addresses, and analytics may report the same page twice. A single 301 from one form to the other removes the doubt and costs nothing, so it is worth doing on any site you control.

3. Should I use a 301 or a 308 for trailing-slash redirects?

For ordinary pages either is fine, because both are permanent and search engines treat them the same way. The difference is that a 308 requires the browser to repeat the same request method, so a form POST stays a POST. That makes 308 the safer choice when the rule could catch form handlers or API endpoints. Some frameworks, including Next.js, use 308 by default for this redirect, which you can leave as it is.

4. Will changing to the other slash form hurt my rankings?

Changing every URL on a site is a small migration, and any migration can cause a period of fluctuation while search engines follow the redirects and update their index. Done properly, with single-hop permanent redirects and every link, canonical and sitemap updated at the same time, most sites settle down. But there is no ranking gain from the switch itself, so only change the form if you have a practical reason, not because one looks tidier.

5. Why does my server add a slash to some URLs but not others?

Usually because some addresses map to real folders on disk and others are handled by the CMS or framework. Apache's DirectorySlash setting and nginx's handling of try_files with a folder both add a slash when the request matches a real directory, while the application router decides what happens to every other path. A folder called team in the web root will get a slash even if your WordPress permalinks do not use one.

6. Should PDF and image addresses have a trailing slash?

No. Files with an extension such as .pdf, .jpg, .png, .css, .js or .xml should be served at their exact file name with no slash after it. A slash turns the address into something that looks like a folder, which can break relative links and confuse caches. Make sure your slash rule skips any path with a file extension, and if a file loads at the slash form as well, find the catch-all route that is serving it.

7. How do I stop a trailing-slash rule from causing a redirect loop?

Loops happen when two layers enforce opposite forms, for example WordPress adding the slash while an .htaccess rule removes it. Find every place that touches the slash: the CMS permalink setting, redirect plugins, the server configuration, the CDN and the framework. Keep exactly one of them and delete the rest. Then test in a private window or with the Redirect Checker, because browsers cache 301 responses and can replay an old loop.

Check every slash variation

The Redirect Checker follows each URL through its full chain, recording every status code, Location header and hop time, so you can see whether a slash redirect stacks on top of your HTTPS and www rules.

Open Redirect Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Redirect Fixes  ·  Multi-Hop Redirect Chains  ·  Canonical Tag Fixes  ·  Redirect Checker Guide  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.