{"id":28399812,"url":"https://github.com/gbuesing/rack-host-redirect","last_synced_at":"2025-08-30T06:45:14.325Z","repository":{"id":8888618,"uuid":"10607600","full_name":"gbuesing/rack-host-redirect","owner":"gbuesing","description":"Rack middleware to redirect legacy domains","archived":false,"fork":false,"pushed_at":"2018-06-06T13:24:51.000Z","size":22,"stargazers_count":82,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-22T14:45:48.394Z","etag":null,"topics":["rack","rack-middleware","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gbuesing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-10T19:24:52.000Z","updated_at":"2023-11-07T16:07:16.000Z","dependencies_parsed_at":"2022-08-08T15:16:02.404Z","dependency_job_id":null,"html_url":"https://github.com/gbuesing/rack-host-redirect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gbuesing/rack-host-redirect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbuesing%2Frack-host-redirect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbuesing%2Frack-host-redirect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbuesing%2Frack-host-redirect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbuesing%2Frack-host-redirect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbuesing","download_url":"https://codeload.github.com/gbuesing/rack-host-redirect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbuesing%2Frack-host-redirect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272815818,"owners_count":24997661,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["rack","rack-middleware","ruby"],"created_at":"2025-06-01T08:11:02.378Z","updated_at":"2025-08-30T06:45:14.305Z","avatar_url":"https://github.com/gbuesing.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Rack::HostRedirect\n==================\n\nA lean and simple Rack middleware that 301 redirects requests from one host to another.\n\nThis is useful for environments where it's difficult or impossible to implement this via Nginx/Apache configuration (e.g. Heroku.)\n\nI'm using this to redirect traffic from a *.herokuapp.com subdomain to a custom domain, and to redirect the www subdomain to the bare domain.\n\nConfiguration below is for Rails, but this middleware should also work just fine with Sinatra and bare Rack apps.\n\n\nRails configuration\n-------------------\n\nin Gemfile:\n\n```ruby\ngem 'rack-host-redirect'\n```\n\nin config/environments/production.rb:\n\n```ruby\nconfig.middleware.use Rack::HostRedirect, {\n  'myapp.herokuapp.com' =\u003e 'www.myapp.com'\n}\n```\n\nWith this configuration, all requests to ```myapp.herokuapp.com``` will be 301 redirected to ```www.myapp.com```.\n\nPath, querystring and protocol are preserved, so a request to:\n\n    https://myapp.herokuapp.com/foo?bar=baz\n\nwill be 301 redirected to:\n\n    https://www.myapp.com/foo?bar=baz\n\nAddtional host redirections can be specified as key-value pairs in the host mapping hash:\n\n```ruby\nconfig.middleware.use Rack::HostRedirect, {\n  'myapp.herokuapp.com' =\u003e 'www.myapp.com',\n  'old.myapp.com'       =\u003e 'new.myapp.com'\n}\n```\n\nMultiple hosts that map to the same redirect destination host can be specified by an Array key:\n\n```ruby\nconfig.middleware.use Rack::HostRedirect, {\n  %w(myapp.herokuapp.com foo.myapp.com) =\u003e 'www.myapp.com'\n}\n```\n\nURI methods to set for redirect location can be specified as a hash value:\n\n```ruby\n# Don't preserve path or query on redirect:\nconfig.middleware.use Rack::HostRedirect, {\n  'bar.myapp.com' =\u003e {host: 'www.myapp.com', path: '/', query: nil}\n}\n```\n\nWhen specifying a URI methods hash, the ```:host``` key is required; all other URI keys are optional.\n\n\nSkip redirect for special cases (e.g. Let's Encrypt)\n---\n\nWhen you specify a host redirect, it will redirect all requests to that host, but if you need certain exclusions to this -- e.g. you're handling a Let's Encrypt challenge request in your app, so you need to let that pass through -- you can do so via passing in a Proc to the ```:exclude``` key:\n\n```ruby\n# Allow ACME challenge request to pass through, redirect everything else:\nconfig.middleware.use Rack::HostRedirect, {\n  'www.example.com' =\u003e {\n    host: 'example.com', \n    exclude: -\u003e (request) { request.path.start_with?('/.well-known/acme-challenge/') }\n  }\n}\n```\n\nThe proc will be called for each request with the ```Rack::Request``` object. If the proc returns a truthy value, the request will pass through without a redirect.\n\n\nWith ActionDispatch::SSL\n------------------------\n\nIf your app is setting ```config.force_ssl = true``` and you're redirecting from a domain for which you don't maintain certs, you should insert ```Rack::HostRedirect``` ahead of ```ActionDispatch::SSL``` in the middleware stack, so that the redirect happens before the SSL upgrade:\n\n```ruby\nconfig.middleware.insert_before ActionDispatch::SSL, Rack::HostRedirect, {\n  'www.legacy-domain.com' =\u003e 'www.myapp.com'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbuesing%2Frack-host-redirect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbuesing%2Frack-host-redirect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbuesing%2Frack-host-redirect/lists"}