Giter VIP home page Giter VIP logo

kirby3-redirects's Introduction

Kirby 3 Redirects

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
 
M O N E Y
Github sponsor Patreon Buy Me a Coffee Paypal dontation Hire me

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

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.
block.enabled true Block various routes of other popular CMS

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

kirby3-redirects's People

Contributors

bnomei avatar splorp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kirby3-redirects's Issues

Add option to ignore or respect trailing slashes

I wonder if it would make sense to have an option to define wether a trailing slash is respected or not. Right now I need to add two redirects for the same resource.

1./test -> /test-new
2. /test/ -> /test-new

We could surly add a rule to the .htaccess and remove all trailing slashes intially but that would result in two redirects (one by the webserver and one by your plugin) which is a bit messy and totally unnecessary.

What do you think about that idea?

Redirects not working in Kirby 4?

After upgrading to Kirby 4, any URL I have saved as a redirect is returning a 404.

Any advice on what I might be doing wrong?

  • Kirby 4.0.1
  • Redirects 1.12.0

Current Kirby version requirements?

Hi Bruno.

I have yet to install the 4.2.0 version of the plugin on my K3 site, mainly because the Kirby version requirements are not mentioned anywhere.

I did notice that composer.json does not list getkirby/cms in the require element, but it does list it for require-dev.

"require": {
    "php": ">=8.1",
    "getkirby/composer-installer": "^1.2"
},
"require-dev": {
    "getkirby/cms": "^4.1.0",
    "php-coveralls/php-coveralls": "^2.4",
    "phpunit/phpunit": "^9.5",
    "spatie/ray": "^1.41"
},

Can I assume that 4.2.0 still works with K3?

Class Redirects not found on some mashines

On some machines, the class Redirects could not be found because filename of redirects.php begins with small letter. The filename has to begin with a capital letter (PSR Standard).

Fetching Codes

Fetching response codes makes the panel unresponsive with a growing number of redirects. It's works with a few entries in the redirects fields but we have a list of 160 redirects and the panel hasn't finished loading after 30 seconds.

Installation error


Warning: require_once(/.../site/plugins/kirby3-redirects/vendor/autoload.php): failed to open stream: No such file or directory in /.../site/plugins/kirby3-redirects/index.php on line 3

Fatal error: require_once(): Failed opening required '/.../site/plugins/kirby3-redirects/vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php7.2.1/lib/php') in /.../site/plugins/kirby3-redirects/index.php on line 3

Error on plugin installation

After I installed the plugin, an error occured.
Class "Bnomei\Redirects" not found on /site/plugins/kirby3-redirects/index.php29

No data have been added to site.txt.
Removing plugin make the website work again.

Any idea?

Notes

  • installation was made using Composer
  • Current PHP version is 8.0.12
  • Kirby is up to date: 3.6.0
  • behavior is weird as sometimes the error only came after accessing 2 or 3 URL on the website...

Capture d’écran 2021-11-30 à 06 44 07

Order fails by hits / path etc.

Is there any plan to add possibility to order failure's list by other columns then ID?

It might be useful to solve issues with most hits first.

subfolder

But I created a new variable $sitebase = \Kirby\Http\Url::path($siteurl); containing the installation base. If I prepend this to the from URL everything works as expected: $fromuri = $sitebase . '/' . trim(str_replace($siteurl, '', $fromuri), '/');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.