Skip to content

How to Add a Trailing Slash to WordPress URLs (Without Breaking Admin or Plugins)

Add trailing slash to wordpress urls

URLs with and without a trailing slash are technically different to search engines but can often serve the same content. This can lead to duplicate content issues, messy analytics, and an inconsistent user experience.

In this guide, you’ll learn how to automatically enforce trailing slashes on all URLs in WordPress while excluding important paths like the admin area, plugin resources, and REST API.

Why Trailing Slashes Matter

Consider these two URLs:

They look the same, but search engines and servers treat them as two separate pages. That can split SEO value, cause duplicate content issues, and impact analytics.

Benefits of consistent trailing slashes:

  • Improved SEO clarity.
  • Cleaner analytics.
  • Better user experience.

WordPress sometimes handles this, but if you have custom permalinks, plugins, or complex setups, it’s better to add trailing slashes manually.

How to Add a Trailing Slash Using .htaccess

This method works only for Apache-based servers (most shared hosting). If you’re using NGINX, you’ll need a different approach.

Step-by-step Instructions

1. Backup your .htaccess file
Before making any changes, download and save a backup of your current .htaccess file.

2. Locate and edit your .htaccess file
This file is found in the root directory of your WordPress installation is usually /public_html/.

3. Add the following rules before the # BEGIN WordPress line:

# Enforce trailing slash on URLs

# Exclude WordPress admin, plugin paths, and REST API
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{REQUEST_URI} !^/wp-content/plugins [NC]
RewriteCond %{REQUEST_URI} !^/wp-json [NC]

# Only apply to requests without a file extension
RewriteCond %{REQUEST_URI} /+[^\.]+$

# Redirect to same URL with trailing slash if it doesn't already end with one
RewriteRule ^(.+[^/])$ https://www.asadzulfahri.com%{REQUEST_URI}/ [R=301,L]

Make sure to replace https://www.asadzulfahri.com with your own domain name.

4. Save and test
Upload or save the updated file and check your site to confirm everything works as expected.

How to Test It

  • Visit a URL without the slash:
    https://yourdomain.com/sample-page
  • You should be redirected to:
    https://yourdomain.com/sample-page/
  • Test that the WordPress dashboard still works:
    https://yourdomain.com/wp-admin
  • Check that plugins and API paths still load correctly.

Use browser developer tools or an HTTP header checker to confirm it’s a 301 (permanent) redirect.

What About SEO?

When done with a 301 redirect, enforcing trailing slashes is SEO-friendly. It helps:

  • Consolidate link signals to one canonical URL
  • Prevent duplicate content
  • Clean up reporting in analytics tools

SEO plugins like Yoast or Rank Math will automatically adjust to reflect the updated structure.

Troubleshooting Tips

  • Redirect loop? Check if another plugin or redirect rule is interfering.
  • Plugin or admin area broken? Double-check your exclusions for /wp-admin, /wp-content/plugins, and /wp-json.
  • Site not loading? Revert to your .htaccess backup.
  • Running NGINX? Use the appropriate configuration for NGINX instead.

Summary

By adding this small tweak to your .htaccess, you:

  • Ensure every URL ends with a trailing slash.
  • Protect admin, plugin, and API paths from redirect issues.
  • Improve SEO, consistency, and user experience.

It’s a quick fix that solves a subtle but important issue without relying on plugins or heavy customizations.