Right now the `django.contrib.redirects` app only redirects the URL path,
it ignores query parameters. I believe it should be optional for the user
to pass-through query parameters in the redirect; this is especially
important for marketing campaigns where query parameters are used to
identify the source of traffic.
I am happy to do the work, but want to make sure the changes I am proposed
are considered the right way to do this.
I believe this should work as follows:
1. with every redirect, the admin has the ability to optionally include
query parameters, with a second option for query parameter re-writes
described below
2. *if* query parameters are being passed through:
1. if there are no query parameters in the `new_path` field, query
parameters are passed through unmodified
2. if there are query parameters in the `new_path` field and override
parameters is set, then passed query parameters are replaced with the
provided parameters in the `new_path` (parameters not specified in
`new_path` are still passed through untouched)
3. if there are query parameters in the `new_path` field and override
parameters is unset, then passed query parameters replace the provide
parameters in `new_path`
As a simple example of 2.2:
old_path = '/abc/', new_path = '/xyz/?x=1', request = '/abc/?x=2&y=2' ->
redirects to '/xyz/?x=1&y=2'
As a simple example of 2.3:
old_path = '/abc/', new_path = '/xyz/?x=1', request = '/abc/?x=2&y=2' ->
redirects to '/xyz/?x=2&y=2'
I propose the following changes:
- add an optional `include_query_parameters` boolean to the Redirect
model, default=False
- this guarantees all existing and newly-created redirects are
unaffected by the new behavior
- add an optional `overwrite_parameters` boolean to the Redirect model,
default=True
- this guarantees all newly-created redirects default to passing
specified parameters if the user sets `include_query_parameters` to True
- modify the middleware to implement the behaviors described above
Thanks for feedback and suggestions!
jeff
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/0cd3124b-d40e-4afa-a6b8-34d5d6ecb141%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.