bnomei/kirby3-redirects

Setup performant HTTP Status Code Redirects from within the Kirby Panel

4.3.0 2024-11-18 12:06 UTC

README

Release Downloads Build Status Coverage Status Maintainability Twitter

Setup performant HTTP Status Code Redirects from within the Kirby Panel.

Kirby 3 Redirects can redirect any request URI to any response URI. It can also handle querystrings and regex.

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.

Commercial Usage


Support open source!

This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?

Be kind. Share a little. Thanks.

‐ Bruno
 

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.

Usage

In the structure field or using the provided site methods add Request-URIs fromuri like

  • projects/cool
  • projects?id=123
  • projects/cool.html
  • projects\/.*\.html
  • blog\/(?P<year>\d{4})_(?P<slug>.*)\.html

and set Response-URIs touri like

  • projects/changed-slug
  • https://exter.nal
  • blog/$year/$slug

as well as a HTTP Status Code code like 301 or 302.

This makes it the ideal choice when porting a non Kirby project.

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'],
]);

Protecting your Kirby from Bots

This plugin will block various routes of other popular CMS. It is enabled by default and will reduce the load on your website caused by bots looking for vulnerabilities in other CMS.

  • Wordpress
  • Joomla
  • Drupal
  • Magento
  • Shopify

Settings

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