title: Permanently Redirect http to https on Google App Engine Flexible with Django
body: <p>I'm working on a project that uses Google Cloud Platform's App Engine in the Python 3 Flexible Environment using Django, and I'm trying to permanently redirect all requests over <code>http</code> to <code>https</code> for all routes, but so far have not been successful. I can access the site over <code>https</code>, but only if explicitly written in the address bar.</p>
  
  <p>I've looked at this post: <a href="https://stackoverflow.com/questions/33878825/how-to-permanently-redirect-http-and-www-urls-to-https">How to permanently redirect `http://` and `www.` URLs to `https://`?</a> but did not find the answer useful.</p>
  
  <p>The app works properly in every sense except for the redirecting. Here is my <code>app.yaml</code> file:</p>
  
  <pre><code># [START runtime]
  runtime: python
  env: flex
  entrypoint: gunicorn -b :$PORT myproject.wsgi
  
  runtime_config:
    python_version: 3
  # [END runtime]
  </code></pre>
  
  <p>In <code>myproject/settings.py</code> I have these variables defined:</p>
  
  <pre><code>SECURE_SSL_REDIRECT = True
  SESSION_COOKIE_SECURE = True
  CSRF_COOKIE_SECURE = True
  SECURE_PROXY_SSL_HEADER = ('HTTP-X-FORWARDED-PROTO', 'https')
  </code></pre>
  
  <p>On my local machine, when I set <code>SECURE_SSL_REDIRECT</code> to <code>True</code>, I was redirected to <code>https</code> properly, even though SSL is not supported on localhost. In production, I am still able to access the site using just <code>http</code>.</p>
  
  <p>Is there something I'm missing or doing wrong to cause the redirect not to happen?</p>