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
- Add the middleware to your
MIDDLEWARElist insettings.py. It is recommended to place it before Django'sCommonMiddleware.
# settings.py
MIDDLEWARE = [
'remove_slash.middleware.RemoveTrailingSlashMiddleware',
# ... other middleware
]
- (Optional) By default, the middleware ignores URLs starting with
/admin/. You can customize this by addingREMOVE_SLASH_IGNORE_PREFIXESto yoursettings.py.
# settings.py
REMOVE_SLASH_IGNORE_PREFIXES = ['/admin/', '/api/v1/']
That's it! The middleware will now automatically handle redirects.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bear_django_remove_trailing_slash-0.1.0.tar.gz.
File metadata
- Download URL: bear_django_remove_trailing_slash-0.1.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d58c7b1183ac3203dcae68a22ab69bfeb59b9db23134a9fb9469115e73a2940
|
|
| MD5 |
233df6f560e9e5e6f1204df024fc21a0
|
|
| BLAKE2b-256 |
5100fb912bbf323e58a454d756a652a62e43857c58a7fe4ee66fcda4c85da964
|
File details
Details for the file bear_django_remove_trailing_slash-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bear_django_remove_trailing_slash-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a2ecf6a4a6d6da80a39995d61842d94f6835ec9c48ebb67fe86996cc4610cb8
|
|
| MD5 |
4e1e46be07046a8da85d0c331f7454c9
|
|
| BLAKE2b-256 |
cbc83cba3c0b0b7ca8c3008404250fa7a276ed4abc06f32c46a6d5db06d2785d
|