Redirect works when I put a slash at the end of the URL in Drupal

I am trying to redirect a URL using the Drupal redirect module, but it doesn’t work. It works when I try to use a slash at the end of the URL. The content type is page.

For example -

Redirecting example.com/a/b to example.com/b/c, and it works if I hit this URL example.com/a/b/

Redirect module version -  8.x-1.11
Drupal - 10.4.6
PHP - 8.3

Any help is highly appreciated.

This is a common issue with Drupal’s Redirect module and how it handles trailing slashes in URLs. Here’s what’s going on and how to fix it:

Problem Summary

You created a redirect:

/a/b → /b/c

But this redirect only works when visiting /a/b/ (with trailing slash). If someone visits /a/b (no slash), it doesn’t work.

Why This Happens

Drupal considers /a/b and /a/b/ as distinct paths at the routing level, especially in clean URLs. So the Redirect module doesn’t automatically match both versions unless configured explicitly.

Also, since you’re on Redirect 8.x-1.11, this version doesn’t normalize URLs or automatically apply the redirect to both versions.

Solution Options

Option 1: Create two redirects (manual but reliable)

Manually create both:

  • /a/b/b/c
  • /a/b//b/c

This ensures both versions are covered regardless of how users type the URL.

Option 2: Enable path normalization (automatic)

Enable Redirect path normalization, which handles redirecting /a/b/ to /a/b or vice versa.

Steps:

  1. Go to Configuration → Search and metadata → Redirect settings.
  2. Look for “Redirect Trailing Slash” and enable it.
  • This can normalize slashes so one redirect covers both.
  1. Optionally enable “Redirect lowercase URLs” to handle case consistency.

Then clear cache:

drush cr

Note: This still may not retroactively fix already-created redirects—you might need to recreate them.

Option 3: Use .htaccess (if you want full control)

As a last resort, you can add Apache rewrite rules to ensure trailing slashes are always added or removed uniformly:

# Redirect /a/b to /a/b/ permanently
RewriteCond %{REQUEST_URI} ^/a/b$
RewriteRule ^(.*)$ /$1/ [R=301,L]

But this is more appropriate when you have many such issues across the site and want strict slash rules.

Recommendation

Start with Option 1 (create both redirects) and enable the path normalization setting to avoid this in future redirects.