{"id":13577007,"url":"https://github.com/adamkdean/redirect","last_synced_at":"2025-03-21T00:38:21.128Z","repository":{"id":42658906,"uuid":"190247303","full_name":"adamkdean/redirect","owner":"adamkdean","description":"Redirection lightweight companion container for the nginx-proxy.","archived":false,"fork":false,"pushed_at":"2023-03-05T23:36:35.000Z","size":375,"stargazers_count":19,"open_issues_count":9,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-06T18:43:02.934Z","etag":null,"topics":["docker","proxy"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamkdean.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-06-04T17:18:22.000Z","updated_at":"2023-03-16T11:04:51.000Z","dependencies_parsed_at":"2024-01-16T20:25:43.542Z","dependency_job_id":"4543d688-66e0-43f4-823a-873891b51d0c","html_url":"https://github.com/adamkdean/redirect","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/adamkdean%2Fredirect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamkdean%2Fredirect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamkdean%2Fredirect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamkdean%2Fredirect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamkdean","download_url":"https://codeload.github.com/adamkdean/redirect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717364,"owners_count":20498284,"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":["docker","proxy"],"created_at":"2024-08-01T15:01:16.852Z","updated_at":"2025-03-21T00:38:21.107Z","avatar_url":"https://github.com/adamkdean.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)\n[![](https://img.shields.io/docker/stars/adamkdean/redirect.svg)](https://hub.docker.com/r/adamkdean/redirect 'DockerHub') [![](https://img.shields.io/docker/pulls/adamkdean/redirect.svg)](https://hub.docker.com/r/adamkdean/redirect 'DockerHub')\n\n# redirect\n\n`adamkdean/redirect` is a lightweight companion container for the nginx-proxy. It allows you to easily redirect hostnames, such as in the case of non-www to www.\n\n## Versions\n\n- `latest`, `1.2`, `1.2.5` current version\n- `1.1`, `1.1.0` pre-multihost version (4 April 2021 and before)\n\n## Usage (standalone)\n\nThe container can be ran as a standalone container, that either redirects all requests or redirects requests based on a per host basis.\n\n### Single host\n\nTo run as single host mode, simply provide a redirection location and (optionally) a status code and preserve url flag. All requests coming into port 80 in this case will be redirected to the location provided.\n\n```\ndocker run \\\n  --detach \\\n  --publish 80:80 \\\n  --env REDIRECT_STATUS_CODE=307 \\\n  --env REDIRECT_LOCATION=\"http://www.example.com\" \\\n  --env PRESERVE_URL=true \\\n  adamkdean/redirect\n```\n\n### Multiple hosts\n\nYou can also run in multiple host mode by providing a configuration file mapping source hosts to destinations, and (optionally again) providing a status code and preserve url flag override. The default host file location is `/etc/redirect/hosts.json` but you can override this by setting `HOSTS_FILE_PATH`.\n\nFor example, we could omit the environment variables used in the single host mode, and simply map in a configuration file:\n\n```\ndocker run \\\n  --detach \\\n  --publish 80:80 \\\n  --volume $(pwd)/hosts.json:/etc/redirect/hosts.json \\\n  adamkdean/redirect\n```\n\nwhere `hosts.json` is a JSON file containing an array of configuration options:\n\n```\n[\n  {\n    \"source\": \"example.com\",\n    \"destination\": \"www.example.com\",\n    \"preserveUrl\": true\n  },\n  {\n    \"source\": \"another-example.com\",\n    \"destination\": \"https://www.another-example.com\",\n    \"statusCode\": 303\n  }\n]\n```\n\n`source` and `destination` are required, but `preserveUrl` (default: false) and `statusCode` (default: 307) aren't.\n\nIf you don't specify the protocol in the destination, it will use the current request protocol. If you're running behind nginx-proxy, this will be http and will add an extra hop in.\n\n#### Overriding host file path\n\nYou can use `HOSTS_FILE_PATH` to override the host file path like so:\n\n```\ndocker run \\\n  --detach \\\n  --publish 80:80 \\\n  --env HOSTS_FILE_PATH=/var/config.json\n  --volume $(pwd)/hosts.json:/var/config.json \\\n  adamkdean/redirect\n```\n\n\n## Usage (nginx-proxy)\n\nIt works better if it's used with [nginx-proxy/nginx-proxy](https://github.com/nginx-proxy/nginx-proxy).\n\nWith `nginx-proxy` you can expose multiple hostnames like below:\n\n```\nversion: '2'\n\nservices:\n  nginx-proxy:\n    image: nginx-proxy/nginx-proxy\n    ports:\n      - 80:80\n    volumes:\n      - /var/run/docker.sock:/tmp/docker.sock:ro\n\n  example:\n    image: example\n    environment:\n      - VIRTUAL_HOST=example.com,www.example.com\n```\n\nUsing `adamkdean/redirect`, we can ensure that `www.example.com` is always used.\n\n```\nversion: '2'\n\nservices:\n  nginx-proxy:\n    image: nginx-proxy/nginx-proxy\n    ports:\n      - 80:80\n    volumes:\n      - /var/run/docker.sock:/tmp/docker.sock:ro\n\n  redirect:\n    image: adamkdean/redirect\n    environment:\n      - VIRTUAL_HOST=example.com\n      - REDIRECT_LOCATION=\"http://www.example.com\"\n      - REDIRECT_STATUS_CODE=301\n      - PRESERVE_URL=true\n\n  example:\n    image: example\n    environment:\n      - VIRTUAL_HOST=www.example.com\n```\n\n## Configuration\n\n### Single host mode\n\n`REDIRECT_LOCATION` should be set to the uri that you want to redirect to.\n\n`REDIRECT_STATUS_CODE` defaults to 307, but you can set it to:\n\n- `301` for Moved Permanently\n- `302` for Found\n- `303` for See Other\n- `307` for Temporary Redirect\n\n`PRESERVE_URL` can be set to `true` to enable URLs to be preserve. When set to false, requests will redirect to the location, so `https://example.com/posts/24` will redirect to `https://www.example.com/`. When set to true, it will redirect to `https://www.example.com/posts/24` etc.\n\n### Multiple host mode\n\n`HOSTS_FILE_PATH` defaults to `/etc/redirect/hosts.json` but this can be overridden. See above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamkdean%2Fredirect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamkdean%2Fredirect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamkdean%2Fredirect/lists"}