{"id":15658968,"url":"https://github.com/bnomei/kirby3-redirects","last_synced_at":"2025-05-09T00:04:33.132Z","repository":{"id":37548979,"uuid":"152279796","full_name":"bnomei/kirby3-redirects","owner":"bnomei","description":"Setup HTTP Status Code Redirects from within the Kirby Panel","archived":false,"fork":false,"pushed_at":"2024-11-29T14:58:17.000Z","size":334,"stargazers_count":24,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-09T00:04:12.909Z","etag":null,"topics":["301","302","307","308","header","kirby-cms","kirby-plugin","kirby4","kirby5","performance","redirect","redirects","status-codes"],"latest_commit_sha":null,"homepage":"https://forum.getkirby.com/t/kirby3-redirects-setup-http-status-code-redirects-form-within-the-panel/23581","language":"PHP","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/bnomei.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bnomei","patreon":"bnomei","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://buymeacoff.ee/bnomei","https://paypal.me/bnomei"]}},"created_at":"2018-10-09T15:56:09.000Z","updated_at":"2025-02-25T13:07:48.000Z","dependencies_parsed_at":"2024-11-23T17:30:34.740Z","dependency_job_id":null,"html_url":"https://github.com/bnomei/kirby3-redirects","commit_stats":{"total_commits":78,"total_committers":3,"mean_commits":26.0,"dds":"0.21794871794871795","last_synced_commit":"fc6408df371d1c6e02bed134a1e4655420bf2b90"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-redirects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-redirects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-redirects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-redirects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnomei","download_url":"https://codeload.github.com/bnomei/kirby3-redirects/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166514,"owners_count":21864475,"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":["301","302","307","308","header","kirby-cms","kirby-plugin","kirby4","kirby5","performance","redirect","redirects","status-codes"],"created_at":"2024-10-03T13:14:30.842Z","updated_at":"2025-05-09T00:04:33.088Z","avatar_url":"https://github.com/bnomei.png","language":"PHP","funding_links":["https://github.com/sponsors/bnomei","https://patreon.com/bnomei","https://buymeacoff.ee/bnomei","https://paypal.me/bnomei","https://www.buymeacoffee.com/bnomei"],"categories":[],"sub_categories":[],"readme":"# Kirby Redirects\n\n[![Kirby 5](https://flat.badgen.net/badge/Kirby/5?color=ECC748)](https://getkirby.com)\n![PHP 8.2](https://flat.badgen.net/badge/PHP/8.2?color=4E5B93\u0026icon=php\u0026label)\n![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-redirects?color=ae81ff\u0026icon=github\u0026label)\n![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-redirects?color=272822\u0026icon=github\u0026label)\n[![Coverage](https://flat.badgen.net/codeclimate/coverage/bnomei/kirby3-redirects?icon=codeclimate\u0026label)](https://codeclimate.com/github/bnomei/kirby3-redirects)\n[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-redirects?icon=codeclimate\u0026label)](https://codeclimate.com/github/bnomei/kirby3-redirects/issues)\n[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da\u0026icon=discord\u0026label)](https://discordapp.com/users/bnomei)\n[![Buymecoffee](https://flat.badgen.net/badge/icon/donate?icon=buymeacoffee\u0026color=FF813F\u0026label)](https://www.buymeacoffee.com/bnomei)\n\n## Features\n\n- ✏️ Define [HTTP Status Code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection) redirects from within the **Kirby Panel**.\n- 🔀 Setup redirects from any request URI to any response URI, not just Kirby routes.\n- 🕵️ Match on query-strings like `?foo=bar` and forward data with regex `(?P\u003cyear\u003e\\d{4})`.\n- 🛡️ Protects your website from attacks by blocking 50+ routes/patterns of other popular CMS.\n- 🪝 With the hooks you can add custom logic like logging 404s.\n- 🏎️ Highly performant due to caching on repeated valid requests.\n\n## Installation\n\n- unzip [master.zip](https://github.com/bnomei/kirby3-redirects/archive/master.zip) as folder\n  `site/plugins/kirby3-redirects` or\n- `git submodule add https://github.com/bnomei/kirby3-redirects.git site/plugins/kirby3-redirects` or\n- `composer require bnomei/kirby3-redirects`\n\n## Setup: add Redirects section to Site blueprint\n\nAdd the `plugin-redirects` section to your `site.yml`. This will allow you to create redirects in via the Panel or\nprogrammatically.\n\n**site/blueprints/site.yml**\n\n```yaml\nsections:\n    # ...other sections\n    redirects:\n        extends: plugin-redirects3xx\n```\n\n\u003e [!TIP]\n\u003e If you want to able to set all HTTP Status code from within the panel, not just the 3xx range, you can use\n`extends: plugin-redirects` instead.\n\n\u003e [!TIP]\n\u003e Instead of using the site blueprint you can also use the `redirects` section in any pages blueprint as long as you\n\u003e adjust the `bnomei.redirects.map` option accordingly so the plugin knows where to find the redirects.\n\n## Usage\n\nIn the Structure Field within the Panel add a Request-URIs `fromuri`, set a Response-URIs `touri` and a HTTP Status Code `code` like `301` or `302`.\n\n| fromuri                                    | to                      | code  |\n|--------------------------------------------|-------------------------|-------|\n| `projects/cool`                            | `projects/changed-slug` | `301` |\n| `projects/cool.html`                       | `projects/changed-slug` | `301` |\n| `projects\\/.*\\.html`                       | `projects/changed-slug` | `301` |\n| `some/broken-link`                         | `https://exter.nal`     | `301` |\n| `blog\\/(?P\u003cyear\u003e\\d{4})_(?P\u003cslug\u003e.*)\\.html` | `blog/$year/$slug`      | `301` |\n\n## Shielding your website from attacks\n\nThis plugin will **block 50+ routes/patterns** of other popular CMS. It is enabled by default and will reduce the load\non your website caused by bots/attackers looking for vulnerabilities found in other CMS.\n\n- Drupal\n- Joomla\n- Magento\n- Shopify\n- Wordpress\n\nYou can track any redirects, including the blocked requests from the *shield*, using the `redirect:before` and\n`404:before` hooks.\n\n## Hooks\n\nThis plugin will trigger the following hooks, which you could use to build your own tracking or logging.\n\n- `redirect:before($code, $redirect)`\n- `404:before($route, $path, $method)`\n\n**site/config/config.php**\n\n```php\n\u003c?php \nreturn [\n    'hooks' =\u003e [\n        'redirect:before' =\u003e function (int $code, \\Bnomei\\Redirect $redirect) {\n            // do whatever you need, like...\n            monolog('redirect')-\u003einfo($code, [\n                'from' =\u003e $redirect-\u003efrom(), \n                'to' =\u003e $redirect-\u003eto()\n            ]);\n        },\n        '404:before' =\u003e function (\\Kirby\\Http\\Route $route, string $path, string $method) {\n            // do whatever you need, like...\n            F::write(kirby()-\u003eroot('logs').'/404.log', implode(' ', [\n                '['.date('Y-m-d H:i:s').']',\n                '404.ERROR',\n                $method,\n                $path,\n                PHP_EOL,\n            ]), true);\n        },\n    ],\n    // other config...\n];\n```\n\n## Programmatically changing the redirects table\n\nThe site methods `appendRedirects` and `removeRedirects` allow you to programmatically change the redirects table (if\nstored in a Page/Site-Object Field, see `map` config option).\n\n```php\n// add single item\n$success = site()-\u003eappendRedirects(\n    ['fromuri' =\u003e '/posts?id=1', 'touri' =\u003e '/blog/1', 'code' =\u003e 301]\n);\n\n// add multiple items with nested array\n$success = site()-\u003eappendRedirects([\n    ['fromuri' =\u003e '/posts?id=2', 'touri' =\u003e '/blog/2', 'code' =\u003e 301],\n    // ...\n    ['fromuri' =\u003e '/posts?id=999', 'touri' =\u003e '/blog/999', 'code' =\u003e 301],\n]);\n\n// remove single item\n$success = site()-\u003eremoveRedirects(\n    ['fromuri' =\u003e '/posts?id=1', 'touri' =\u003e '/blog/1']\n);\n\n// remove multiple items with nested array\n$success = site()-\u003eremoveRedirects([\n    ['fromuri' =\u003e '/posts?id=3', 'touri' =\u003e '/blog/3'],\n    ['fromuri' =\u003e '/posts?id=5', 'touri' =\u003e '/blog/5'],\n    ['fromuri' =\u003e '/posts?id=7', 'touri' =\u003e '/blog/7'],\n]);\n```\n\n## Cache \u0026 Performance\n\nThe plugin will cache any valid URI request and thus vastly improve performance on repeated requests to that URI. Thus\nthe plugin will not check for redirects at all if it know that the URI will lead to a valid content page in Kirby. When\nthe redirects table is changed or any content is updated via the Panel the cache will be cleared.\n\nFor best performance, set either\nthe [global or plugin-specific cache driver](https://getkirby.com/docs/reference/system/options/cache) to one using the\nserver's memory, not the default using files on the hard disk (even on SSDs). If available, I suggest Redis/APCu or\nleave it at `file` otherwise.\n\n**site/config/config.php**\n\n```php\nreturn [\n  'cache' =\u003e [\n    'driver' =\u003e 'apcu', // or redis\n  ],\n  'bnomei.redirects.cache' =\u003e [\n    'type' =\u003e 'apcu', // or redis\n  ],\n];\n```\n\n## Similar Plugins\n\n- [kirby-retour](https://github.com/distantnative/kirby-retour) while featuring a nice UI and built-in 404 tracking it\n  can only handle Kirby routes (with pattern matching) but not any request URI.\n\n## Settings\n\n| bnomei.redirects.  | Default    | Description                                                                                                                                                            |            \n|--------------------|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| code               | `301`      |                                                                                                                                                                        |\n| querystring        | `true`     | do keep querystring in request URI. example: `https://kirby3-plugins.bnomei.com/projects?id=12` =\u003e `projects?id=12`                                                    |\n| only-empty-results | `false`    | only redirect if the result is empty in the router                                                                                                                     |\n| map                | `callback` | A closure to get the structure from `content/site.txt`. Define you own if you want the section to be in a different blueprint or skip the blueprint and just use code. |\n| shield.enabled     | `true`     | Block various routes of other popular CMS                                                                                                                              |\n\n## Disclaimer\n\nThis plugin is provided \"as is\" with no guarantee. Use it at your own risk and always test it yourself before using it\nin a production environment. If you find any issues,\nplease [create a new issue](https://github.com/bnomei/kirby3-redirects/issues/new).\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nIt is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or\nany other form of hate speech.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-redirects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnomei%2Fkirby3-redirects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-redirects/lists"}