Skip to content

bearablyk/django-remove-trailing-slash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Django Remove Trailing Slash

A simple Django middleware that enforces a "no trailing slash" policy by permanently redirecting (301) any URL ending in a slash to its non-slashed version.

This is useful for SEO purposes to prevent duplicate content indexing.

Features

  • Performs a 301 Permanent Redirect.
  • Preserves query strings.
  • Ignores the root path (/).
  • Allows configurable exclusion of URL prefixes (e.g., /admin/, /api/).

Installation

pip install bear-django-remove-trailing-slash

Usage

  1. Add the middleware to your MIDDLEWARE list in settings.py. It is recommended to place it before Django's CommonMiddleware.
# settings.py
MIDDLEWARE = [
   'remove_slash.middleware.RemoveTrailingSlashMiddleware',
    # ... other middleware
]
  1. (Optional) By default, the middleware ignores URLs starting with /admin/. You can customize this by adding REMOVE_SLASH_IGNORE_PREFIXES to your settings.py.
# settings.py
REMOVE_SLASH_IGNORE_PREFIXES = ['/admin/', '/api/v1/']

That's it! The middleware will now automatically handle redirects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages