bnomei/kirby3-redirects

Setup HTTP Status Code Redirects from within the Kirby Panel

Fund package maintenance!
bnomei

Installs: 527

Dependents: 0

Suggesters: 1

Security: 0

Stars: 12

Watchers: 2

Forks: 0

Open Issues: 0

Type:kirby-plugin

1.5.3 2020-02-15 18:32 UTC

This package is auto-updated.

Last update: 2020-08-28 15:35:44 UTC


README

Release Downloads Build Status Coverage Status Maintainability Twitter

Setup HTTP Status Code Redirects from within the Kirby Panel.

Kirby 3 Redirects can handle Request-URIs like projects?id=123, project/cool.html and send Response-URIs like https://exter.nal. This makes it the ideal choice when porting a non Kirby project.

Similar Plugin

  • kirby-retour but it can only handle Kirby Routes. It is the better choice when updating a Kirby 2 project or creating a brand new Kirby 3 project.

Works well with

  • CSV Plugin to help you import and export data to the redirects structure.

Commerical Usage

This plugin is free but if you use it in a commercial project please consider to

Installation

  • unzip master.zip as folder site/plugins/kirby3-redirects or
  • git submodule add https://github.com/bnomei/kirby3-redirects.git site/plugins/kirby3-redirects or
  • composer require bnomei/kirby3-redirects

Setup

Add the plugin-redirects section to your site.yml and add redirects in the panel.

site.yml

sections:
  # ...other sections
  redirects:
    extends: plugin-redirects3xx

If you need all http codes you can use extends: plugin-redirects instead which calls the api to retrieve them (once for each redirect). This is not advised if you have a lot of redirects.

Since v1.1.0 the plugin will register itself with a route:before-hook and take care of the redirecting automatically. Many thanks to Sebastian Aschenbach for suggesting this solution.

Site Methods

The site methods appendRedirects and removeRedirects allow you to programmatically change the redirects table (if stored in a Page/Site-Object).

// add single item
$success = site()->appendRedirects(
    ['fromuri'=>'/posts?id=1', 'touri'=>'/blog/1', 'code'=>301]
);

// add multiple items with nested array
$success = site()->appendRedirects([
    ['fromuri'=>'/posts?id=2', 'touri'=>'/blog/2', 'code'=>301],
    // ...
    ['fromuri'=>'/posts?id=999', 'touri'=>'/blog/999', 'code'=>301],
]);

// remove single item
$success = site()->removeRedirects(
    ['fromuri'=>'/posts?id=1', 'touri'=>'/blog/1']
);

// remove multiple items with nested array
$success = site()->removeRedirects([
    ['fromuri'=>'/posts?id=3', 'touri'=>'/blog/3'],
    ['fromuri'=>'/posts?id=5', 'touri'=>'/blog/5'],
    ['fromuri'=>'/posts?id=7', 'touri'=>'/blog/7'],
]);

Settings

bnomei.redirects. Default Description
code 301
querystring true do keep querystring in request URI. example: https://kirby3-plugins.bnomei.com/projects?id=12 => projects?id=12
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.

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

Credits

This plugins is similar yet way less powerful than K2 version of