Hi all,
I want to propose a change to the LocaleMiddlware or CommonMiddleware and wanted to get some feedback first. Let's assume one uses both CommonMiddleware and LocaleMiddleware and APPEND_SLASH is set to True.
i18n_patterns = ('',
url(r'^about/$', 'about')
)
If one requests
http://example.com/about this currently results in a redirect chain:
http://example.com/en/about (302 or 301 - depending on LocaleMiddleware.response_redirect_class)
http://example.com/en/about/ (301)
For SEO reasons, one should keep redirect chains as short as possible [1]. It would be nice to only make one redirect directly to /en/about/ instead - at least if LocaleMiddleware uses the same kind of redirect as the CommonMiddleware uses.
In your opinion, is that something that is worth addressing?
It's pretty easy to add slash injection to the LocaleMiddleware, as it already checks whether a path with a slash appended would resolve to a valid URL [2].
Alternatively, one could check redirect targets in process_response of the CommonMiddleware, check for valid URLs and append slashes if needed. That would probably be cleaner, but AFAICS requires calling is_valid_path again.
Any thoughts?
I could open a ticket and submit a patch/tests/documentation if it had a chance of being integrated.
Thanks for your feedback,
Ludwig
[1]
http://www.jamesburton.net/chained-301-redirects-google-search-impact/[2]
https://github.com/django/django/blob/master/django/middleware/locale.py#L45