{"id":23440771,"url":"https://github.com/dabapps/django-enforce-host","last_synced_at":"2025-04-13T09:13:01.960Z","repository":{"id":26924276,"uuid":"111932897","full_name":"dabapps/django-enforce-host","owner":"dabapps","description":"Middleware to redirect requests to a canonical host","archived":false,"fork":false,"pushed_at":"2024-03-20T16:58:57.000Z","size":31,"stargazers_count":17,"open_issues_count":1,"forks_count":2,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-06T11:47:13.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-24T15:31:30.000Z","updated_at":"2024-01-19T21:49:37.000Z","dependencies_parsed_at":"2022-08-18T21:30:55.739Z","dependency_job_id":null,"html_url":"https://github.com/dabapps/django-enforce-host","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-enforce-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-enforce-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-enforce-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-enforce-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabapps","download_url":"https://codeload.github.com/dabapps/django-enforce-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217146,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T16:18:34.952Z","updated_at":"2025-04-13T09:13:01.938Z","avatar_url":"https://github.com/dabapps.png","language":"Python","readme":"django-enforce-host\n===================\n\n[![pypi release](https://img.shields.io/pypi/v/django-enforce-host.svg)](https://pypi.python.org/pypi/django-enforce-host)\n\nSometimes, it's unavoidable that multiple URLs point at the same app - for example, on Heroku, all apps get a `.herokuapp.com` address, as well as any custom domains that are pointed at them.\n\nThis is a simple Django middleware that redirects all traffic from hosts other than the one(s) you specify to your canonical URL.\n\nTested against Django 3.2 and 4.0, 4.1 and 4.2 on Python 3.8, 3.9, 3.10 and 3.11.\n\n### Installation\n\nInstall from PyPI\n\n    pip install django-enforce-host\n\nIn your `MIDDLEWARE` setting, add the middleware just after the `SecurityMiddleware`:\n\n    MIDDLEWARE = [\n        # Django's SecurityMiddleware will handle HTTP -\u003e HTTPS redirects\n        # before the EnforceHostMiddleware redirects to the canonical domain\n        'django.middleware.security.SecurityMiddleware',\n        'enforce_host.EnforceHostMiddleware',\n        ... other middleware\n    ]\n\nSet the following setting to be either a single allowed host, or a list of allowed hosts:\n\n    ENFORCE_HOST = 'yourapp.com'\n\nThat's it!\n\n## Code of conduct\n\nFor guidelines regarding the code of conduct when contributing to this repository please review [https://www.dabapps.com/open-source/code-of-conduct/](https://www.dabapps.com/open-source/code-of-conduct/)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabapps%2Fdjango-enforce-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabapps%2Fdjango-enforce-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabapps%2Fdjango-enforce-host/lists"}