Skip to content

Custom middleware for django redirect app with url parameters support.

Notifications You must be signed in to change notification settings

s-steephan/django-custom-redirect-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Custom Middleware for Django Redirect App

Default django redirect app middleware is not support url parameters. It will throw 404 error when URL have parameters.

This custom-redirect-middleware introduced to handle url parameters. So, this custom middleware will handle all the below cases with/without trailing slash in URL.

  • URL with no parameters.

  • URL with one parameter.

  • URL with more than one parameter.

What this middleware actually do:


  • Simply separate URL parameters from full_absolute_path.

  • Next get exact redirect_path of separated full_absolute_path form django.contrib.redirects database.

  • Then append the URL parameters which separated from full_absolute_path is to redirect_path.


  • Download custom redirect middleware custom redirect middleware

  • Place inside your Django app.

  • Replace 'django.contrib.redirects.middleware.RedirectFallbackMiddleware' or add bellow line in MIDDLEWARE of your settings.py.

Note that the order of MIDDLEWARE matters. Generally, you can put RedirectMiddleware at the end of the list, because it’s a last resort. Refer here.

'your_django_app_name.custom_redirect_middleware.CustomRedirectFallbackMiddleware'

Thats it.

Inspired by this stackoverflow question.

About

Custom middleware for django redirect app with url parameters support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages