Friday, September 16, 2016

Random 404 instead of 301 for URLs without trailing slash

Hello,

I am running a site that uses Django 1.8 and Django CMS 3.2. The site is deployed using gunicorn and nginx. Now I noticed a strange, hard to debug issue: When accessing a URL without trailing slash, I expect a redirect to the correct URL with the trailing slash appended, as per the APPEND_SLASH setting. This usually works, but sometimes I get a 404 instead of the correct 301. I can reproduce this using curl:

$ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
HTTP/1.1 404 NOT FOUND
Server: nginx/1.6.2
Date: Fri, 16 Sep 2016 15:54:40 GMT
Content-Type: text/html
Connection: keep-alive
x-xss-protection: 1; mode=block
Content-Language: en
x-content-type-options: nosniff
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:40 GMT; Max-Age=31536000; Path=/

$ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
HTTP/1.1 301 MOVED PERMANENTLY
Server: nginx/1.6.2
Date: Fri, 16 Sep 2016 15:54:42 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
x-xss-protection: 1; mode=block
Content-Language: en
x-content-type-options: nosniff
Vary: Cookie
Location: http://khk.ceres.rub.de/en/research/focus-groups/notions/
X-Frame-Options: SAMEORIGIN
Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:42 GMT; Max-Age=31536000; Path=/

I am a bit clueless why this behaviour is so unpredictable. Any ideas what might be going on here, or how to trace this?

Thanks,
Frederik

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/30d43532-b840-463a-93ff-5989045fc7d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment