HTTPS redirect with Django wsgi.py

Glen Tomkowiak
Nov 8, 2019 · 1 min read

Sometimes you have a tricky situation where you can deploy a Django application but have little control over the front end web server or load balancer terminating your SSL. The code snippet below is an easy way to issue a 301 redirect for any http request. It will also remove the www prefix.

Replace YOUR_DJANGO_SETTINGS.settings with your settings.

    Glen Tomkowiak

    Written by

    Things that interest me: cloud computing, cyber security, DevOps, and mobile / web development. Posts are my own.

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade