zenstruck/redirect-bundle
Composer 安装命令:
composer require zenstruck/redirect-bundle
包简介
Store redirects for your site and keeps statistics on redirects and 404 errors
关键字:
README 文档
README
This bundle adds entities for redirects and 404 errors.
For redirects, 404 errors are intercepted and the requested path is looked up. If a match is found it redirects to the found redirect's destination. The count and last accessed date are updated as well. A redirect form type and validation is available as well.
404 errors can be logged as well. Each 404 error is it's own record in the database. The path, full URL, timestamp, and referer are stored. Storing each error as a separate record allows viewing statistics over time and seeing all the referer URLs. When a redirect is created or updated, 404 records that match it's path are deleted.
Installation
- Install with composer:
composer require zenstruck/redirect-bundle
-
Enable the bundle: This Step is only needed if you are not using Symfony Flex.
// config/bundles.php return [ // ... Zenstruck\RedirectBundle\ZenstruckRedirectBundle::class => ['all' => true], ];
Configuration
NOTE: A NotFound or Redirect or both must be configured.
Redirect
-
Create your redirect class inheriting the MappedSuperClass this bundle provides:
namespace App\Entity; use Zenstruck\RedirectBundle\Model\Redirect as BaseRedirect; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="redirects") */ class Redirect extends BaseRedirect { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; }
-
Set this class in your
zenstruck_redirect.yml:zenstruck_redirect: redirect_class: App\Entity\Redirect
-
Update your schema (or use a migration):
bin/console doctrine:schema:update --force
NotFound
-
Create your not found class inheriting the MappedSuperClass this bundle provides:
namespace App\Entity; use Zenstruck\RedirectBundle\Model\NotFound as BaseNotFound; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="not_founds") */ class NotFound extends BaseNotFound { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; }
-
Set this class in your
zenstruck_redirect.yml:zenstruck_redirect: not_found_class: App\Entity\NotFound
-
Update your schema (or use a migration):
bin/console doctrine:schema:update --force
Form Type
This bundle provides a form type (zenstruck_redirect) for creating/editing redirects.
$redirect = // ... $form = $this->createForm('zenstruck_redirect', $redirect);
You may want to disable the source field for already created redirects:
// new action $redirect = new Redirect(); $form = $this->createForm('zenstruck_redirect', $redirect); // edit action $redirect = // get from database $form = $this->createForm('zenstruck_redirect', $redirect, array('disable_source' => true));
Full Default Configuration
zenstruck_redirect: redirect_class: ~ # Required if not_found_class is not set not_found_class: ~ # Required if redirect_class is not set model_manager_name: ~ # When enabled, when a redirect is updated or created, the NotFound entities with a matching path are removed. remove_not_founds: true
zenstruck/redirect-bundle 适用场景与选型建议
zenstruck/redirect-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64.97k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2012 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redirect」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zenstruck/redirect-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zenstruck/redirect-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zenstruck/redirect-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Advanced TYPO3 redirect management for sys_redirect with regex and host/language-aware matching, CSV/.htaccess import/export, categories and priority, automatic slug redirect workflows, plus hit/log analytics.
SmartResponse simplifies consistent response handling in Laravel: supports Blade, redirect with messages, and JSON format.
This ConcreteCMS/concrete5 addon installs a block type that when added to a page allows you to redirect visitors to this page to another page that you specify or an external URL.
sFire routing for mapping urls to controllers and methods.
Shopware 5 redirecter plugin
统计信息
- 总下载量: 64.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 29
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-02-07