{"id":16351599,"url":"https://github.com/tomeraberbach/redirect-url","last_synced_at":"2025-03-23T01:30:51.940Z","repository":{"id":232609104,"uuid":"784518738","full_name":"TomerAberbach/redirect-url","owner":"TomerAberbach","description":"🎯 Simple rule-based redirecting from one URL to another.","archived":false,"fork":false,"pushed_at":"2024-10-15T03:37:55.000Z","size":604,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T16:13:21.247Z","etag":null,"topics":["http","https","mapping","npm-module","npm-package","path","redirect","redirect-urls","redirects","server","url"],"latest_commit_sha":null,"homepage":"https://npm.im/redirect-url","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomerAberbach.png","metadata":{"files":{"readme":"docs/readme.md","changelog":null,"contributing":null,"funding":null,"license":"license-apache","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-10T02:16:35.000Z","updated_at":"2024-10-15T03:35:15.000Z","dependencies_parsed_at":"2024-10-28T15:20:48.272Z","dependency_job_id":"3e175f7e-5eec-4e94-a0a1-d79d730bfe04","html_url":"https://github.com/TomerAberbach/redirect-url","commit_stats":null,"previous_names":["tomeraberbach/redirect-url"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Fredirect-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Fredirect-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Fredirect-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Fredirect-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomerAberbach","download_url":"https://codeload.github.com/TomerAberbach/redirect-url/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245043843,"owners_count":20551840,"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":["http","https","mapping","npm-module","npm-package","path","redirect","redirect-urls","redirects","server","url"],"created_at":"2024-10-11T01:23:20.822Z","updated_at":"2025-03-23T01:30:51.927Z","avatar_url":"https://github.com/TomerAberbach.png","language":"TypeScript","funding_links":["https://github.com/sponsors/TomerAberbach"],"categories":[],"sub_categories":[],"readme":"**redirect-url** • [**Docs**](globals.md)\n\n---\n\n\u003ch1 align=\"center\"\u003e\n  redirect-url\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/redirect-url\"\u003e\n    \u003cimg src=\"https://badgen.net/npm/v/redirect-url\" alt=\"version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/TomerAberbach/redirect-url/actions\"\u003e\n    \u003cimg src=\"https://github.com/TomerAberbach/redirect-url/workflows/CI/badge.svg\" alt=\"CI\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://unpkg.com/redirect-url/dist/index.min.js\"\u003e\n    \u003cimg src=\"https://deno.bundlejs.com/?q=redirect-url\u0026badge\" alt=\"gzip size\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://unpkg.com/redirect-url/dist/index.min.js\"\u003e\n    \u003cimg src=\"https://deno.bundlejs.com/?q=redirect-url\u0026config={%22compression%22:{%22type%22:%22brotli%22}}\u0026badge\" alt=\"brotli size\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/sponsors/TomerAberbach\"\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86\" alt=\"Sponsor\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  Simple rule-based redirecting from one URL to another.\n\u003c/div\u003e\n\n## Features\n\n- **Flexible:** completely framework agnostic\n- **Powerful:** specify redirects using\n  [`path-to-regexp` patterns](https://github.com/pillarjs/path-to-regexp?tab=readme-ov-file#parameters)\n- **Readable:** configure using a\n  [Netlify `_redirects`](https://docs.netlify.com/routing/redirects#syntax-for-the-redirects-file)-like\n  syntax\n\n## Install\n\n```sh\n$ npm i redirect-url\n```\n\n## Usage\n\n```js\nimport { createRedirectUrl, parseRedirectUrl } from 'redirect-url'\n\nlet redirectUrl = createRedirectUrl([\n  // Nice :)\n  [`/bliss`, `https://www.youtube.com/watch?v=dQw4w9WgXcQ`],\n\n  // Other redirects...\n  { from: `/home`, to: `/`, status: 307 },\n  [`/:splat*\\\\.html`, `/:splat*`],\n])\n// OR\nredirectUrl = parseRedirectUrl(`\n  # Nice :)\n  /bliss            https://www.youtube.com/watch?v=dQw4w9WgXcQ\n\n  # Other redirects...\n  /home             /          307\n  /:splat*\\\\.html   /:splat*\n`)\n\nconsole.log(redirectUrl(`https://example.com/bliss`))\n//=\u003e { url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', status: 302 }\nconsole.log(redirectUrl(`https://example.com/home`))\n//=\u003e { url: 'https://example.com', status: 307 }\nconsole.log(redirectUrl(`https://example.com/about-me.html`))\n//=\u003e { url: 'https://example.com/about-me', status: 302 }\nconsole.log(redirectUrl(`https://example.com/spaghetti`))\n//=\u003e null\n```\n\nThis package can be used with any server or framework, but see some example\nintegrations below. Feel free to send pull requests for more examples!\n\n### Express\n\n```js\nconst redirectsMiddleware = (req, res, next) =\u003e {\n  const result = redirectUrl(req.url)\n  if (result) {\n    res.redirect(result.status, result.url)\n  }\n  next()\n}\n\napp.all(`*`, redirectsMiddleware)\n```\n\n### Remix\n\n[**entry.server**](https://remix.run/docs/en/main/file-conventions/entry.server):\n\n\u003c!-- eslint-disable consistent-return --\u003e\n\n```js\nconst handleRequest = request =\u003e {\n  const result = redirectUrl(request.url)\n  if (result) {\n    return redirect(result.url, result.status)\n  }\n\n  // ...\n}\n\nexport default handleRequest\n```\n\n## API\n\n[See here!](https://github.com/TomerAberbach/redirect-url/blob/main/docs/modules.md)\n\n## Contributing\n\nStars are always welcome!\n\nFor bugs and feature requests,\n[please create an issue](https://github.com/TomerAberbach/redirect-url/issues/new).\n\n## License\n\n[MIT](https://github.com/TomerAberbach/redirect-url/blob/main/license) ©\n[Tomer Aberbach](https://github.com/TomerAberbach) \\\n[Apache 2.0](https://github.com/TomerAberbach/redirect-url/blob/main/license-apache) ©\n[Google](https://github.com/TomerAberbach/redirect-url/blob/main/notice-apache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomeraberbach%2Fredirect-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomeraberbach%2Fredirect-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomeraberbach%2Fredirect-url/lists"}