Created
August 5, 2016 22:11
-
-
Save ebertti/c9ad865c0c5fb6e5a5c213e9cc4260f3 to your computer and use it in GitHub Desktop.
Dreamhost with passenger+python forcing HTTPS redirect 301 on passenger_wsgi.py file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
sys.path.append(os.getcwd()) | |
os.environ['DJANGO_SETTINGS_MODULE'] = "my_project_name.settings" | |
### OLD DJANGO like 1.3 | |
import django.core.handlers.wsgi | |
wsgi_application = django.core.handlers.wsgi.WSGIHandler() | |
### new django versions | |
from django.core.wsgi import get_wsgi_application | |
wsgi_application = get_wsgi_application() | |
def application(environ, start_response): | |
if environ['wsgi.url_scheme'] == 'http': | |
url = 'https://' + environ['HTTP_HOST'] + environ['REQUEST_URI'] | |
start_response('301 Moved Permanently', [('Location', url)]) | |
return [] | |
return wsgi_application(environ, start_response) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment