Skip to main content

A Django middleware that removes trailing slashes from URLs for SEO purposes.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bear_django_remove_trailing_slash-0.1.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file bear_django_remove_trailing_slash-0.1.0.tar.gz.

File metadata

File hashes

Hashes for bear_django_remove_trailing_slash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d58c7b1183ac3203dcae68a22ab69bfeb59b9db23134a9fb9469115e73a2940
MD5 233df6f560e9e5e6f1204df024fc21a0
BLAKE2b-256 5100fb912bbf323e58a454d756a652a62e43857c58a7fe4ee66fcda4c85da964

See more details on using hashes here.

File details

Details for the file bear_django_remove_trailing_slash-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bear_django_remove_trailing_slash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a2ecf6a4a6d6da80a39995d61842d94f6835ec9c48ebb67fe86996cc4610cb8
MD5 4e1e46be07046a8da85d0c331f7454c9
BLAKE2b-256 cbc83cba3c0b0b7ca8c3008404250fa7a276ed4abc06f32c46a6d5db06d2785d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page