Opened 10 years ago

Last modified 10 years ago

#23531 closed New feature

APPEND_SLASHES behavior shouldn't redirect with a 301 — at Initial Version

Reported by: Matt Robenolt Owned by: nobody
Component: Core (URLs) Version: dev
Severity: Normal Keywords: common, middleware, redirect
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Redirecting with a permanent redirect (HttpResponsePermanentRedirect) can lead to 404s and other unexpected behavior when things move around.

For example:

In settings.py, APPEND_SLAHSES = True (the default behavior)

In urls.py url(r'foo/$', ..._

A user visits example.com/foo and gets redirected to example.com/foo/ as expected.

Later, we decide that we don't like slashes in our urls, and change to APPEND_SLASHES = False and change our url route to url(r'foo$', ...

A user visits example.com/foo again (which is now the correct url) and their browser redirects them to example.com/foo/ which is now a 404.

This behavior happens specifically because Django has told it that this redirect is 100% going to happen, so the browser caches it and doesn't ask the server again. In my opinion, it's a bad idea that Django makes this assumption because it has no insight into what future plans are and whatnot.

This behavior has also existed since at least 2007, so I'm not sure how much effort needs to go into changing this moving forward for 1.8+.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top