承接 bnomei/kirby3-redirects 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bnomei/kirby3-redirects

Composer 安装命令:

composer require bnomei/kirby3-redirects

包简介

Setup performant HTTP Status Code Redirects from within the Kirby Panel

README 文档

README

Kirby 5 PHP 8.2 Release Downloads Coverage Maintainability Discord Buymecoffee

Features

  • ✏️ Define HTTP Status Code redirects from within the Kirby Panel.
  • 🔀 Setup redirects from any request URI to any response URI, not just Kirby routes.
  • 🕵️ Match on query-strings like ?foo=bar and forward data with regex (?P<year>\d{4}).
  • 🛡️ Protects your website from attacks by blocking 50+ routes/patterns of other popular CMS.
  • 🪝 With the hooks you can add custom logic like logging 404s.
  • 🏎️ Highly performant due to caching on repeated valid requests.

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 Redirects section to Site blueprint

Add the plugin-redirects section to your site.yml. This will allow you to create redirects in via the Panel or programmatically.

site/blueprints/site.yml

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

Tip

If you want to able to set all HTTP Status code from within the panel, not just the 3xx range, you can use extends: plugin-redirects instead.

Tip

Instead of using the site blueprint you can also use the redirects section in any pages blueprint as long as you adjust the bnomei.redirects.map option accordingly so the plugin knows where to find the redirects.

Usage

In 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.

fromuri to code
projects/cool projects/changed-slug 301
projects/cool.html projects/changed-slug 301
projects\/.*\.html projects/changed-slug 301
some/broken-link https://exter.nal 301
blog\/(?P<year>\d{4})_(?P<slug>.*)\.html blog/$year/$slug 301

Exact redirects

For generated redirect maps with many known 301 redirects, use bnomei.redirects.exact. It is checked before the Panel-managed map and only performs strict request URI lookups. Regex patterns and placeholders are intentionally not processed in this list.

site/config/config.php

return [
    'bnomei.redirects.exact' => fn () => require kirby()->root('site').'/redirects/exact.php',
];

site/redirects/exact.php

<?php

return [
    '/old/path.htm' => '/new/path',
];

Shielding your website from attacks

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

  • Drupal
  • Joomla
  • Magento
  • Shopify
  • Wordpress

You can track any redirects, including the blocked requests from the shield, using the redirect:before and 404:before hooks.

Hooks

This plugin will trigger the following hooks, which you could use to build your own tracking or logging.

  • redirect:before($code, $redirect)
  • 404:before($route, $path, $method)

site/config/config.php

<?php 
return [
    'hooks' => [
        'redirect:before' => function (int $code, \Bnomei\Redirect $redirect) {
            // do whatever you need, like...
            monolog('redirect')->info($code, [
                'from' => $redirect->from(), 
                'to' => $redirect->to()
            ]);
        },
        '404:before' => function (\Kirby\Http\Route $route, string $path, string $method) {
            // do whatever you need, like...
            F::write(kirby()->root('logs').'/404.log', implode(' ', [
                '['.date('Y-m-d H:i:s').']',
                '404.ERROR',
                $method,
                $path,
                PHP_EOL,
            ]), true);
        },
    ],
    // other config...
];

Programmatically changing the redirects table

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

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

Performance

Redirects are checked against exact redirect entries first and then against the configured redirect map. Unmatched public requests are not written to the cache.

Similar Plugins

  • kirby-retour while featuring a nice UI and built-in 404 tracking it can only handle Kirby routes (with pattern matching) but not any request URI.

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
only-empty-results false only redirect if the result is empty in the router
exact null Strict request URI lookup map for generated redirects: ['/old' => '/new']. Runs before map and does not process regex patterns.
exact.code 301 HTTP status code used for exact redirects.
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.
shield.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.

bnomei/kirby3-redirects 适用场景与选型建议

bnomei/kirby3-redirects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.46k 次下载、GitHub Stars 达 25, 最近一次更新时间为 2018 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「firewall」 「redirect」 「placeholder」 「header」 「regex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bnomei/kirby3-redirects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bnomei/kirby3-redirects 我们能提供哪些服务?
定制开发 / 二次开发

基于 bnomei/kirby3-redirects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-09