fromholdio/silverstripe-superlinker-redirection
Composer 安装命令:
composer require fromholdio/silverstripe-superlinker-redirection
包简介
Replace for OOTB Silverstripe Redirector Page, using a SuperLink target to select a much wider range of target types
README 文档
README
Advanced redirector pages and standalone redirects using SuperLink targets.
Overview
Replaces SilverStripe's built-in RedirectorPage with a more powerful system that:
- Supports all SuperLink types (not just internal/external)
- Provides standalone Redirection DataObjects
- Offers HTTP status code selection
- Includes collision detection
- Supports custom URL paths
Requirements
- SilverStripe CMS ^6.0
- fromholdio/silverstripe-superlinker ^4.0.0
- fromholdio/silverstripe-relativeurlfield ^2.0.0
- fromholdio/silverstripe-hidden-pages ^3.0.0
- fromholdio/silverstripe-hasoneedit ^3.0.1
Installation
composer require fromholdio/silverstripe-superlinker-redirection
Run dev/build:
vendor/bin/sake dev/build flush=1
Features
RedirectionPage
A page type that redirects to any SuperLink target.
Features:
- Redirect to any link type (SiteTree, External, Email, File, System, etc.)
- HTTP status code selection (301, 302, 303, 307, 308)
- Hidden from site tree by default
- Automatic redirect on page load
Usage:
$redirector = RedirectionPage::create(); $redirector->Title = 'Old Product Page'; $redirector->URLSegment = 'old-product'; $redirector->write(); // Set redirect target $redirector->RedirectLink()->LinkType = 'sitetree'; $redirector->RedirectLink()->SiteTreeID = $newPage->ID; $redirector->RedirectLink()->write(); $redirector->publishRecursive();
Redirection DataObject
Standalone redirects not tied to pages.
Features:
- Redirect from custom URL paths
- Collision detection with site tree
- HTTP status code selection
- Admin interface for management
Usage:
$redirect = Redirection::create(); $redirect->FromURL = '/old-path'; $redirect->StatusCode = 301; $redirect->write(); // Set redirect target $redirect->RedirectLink()->LinkType = 'external'; $redirect->RedirectLink()->ExternalURL = 'https://example.com/new-path'; $redirect->RedirectLink()->write();
Configuration
HTTP Status Codes
Available status codes:
- 301 - Moved Permanently (default for SEO)
- 302 - Found (temporary redirect)
- 303 - See Other
- 307 - Temporary Redirect (preserves method)
- 308 - Permanent Redirect (preserves method)
Hiding RedirectionPage from Site Tree
Fromholdio\SuperLinkerRedirection\Pages\RedirectionPage: hide_from_hierarchy: true hide_from_cms_menu: false
Force redirections over live pages
By default a RedirectionSuperLink fires only as a 404 fallback: if a published page already exists at the redirection's origin URL, that page is served and the redirect never runs.
Set do_force_redirections to make redirections take precedence over the site tree — a matching redirect then fires even when a live page exists at the URL, checked in onBeforeInit before the page controller renders (comparable to Misdirection's enforce mode):
Fromholdio\SuperLinkerRedirection\Model\RedirectionSuperLink: do_force_redirections: true
- Default is
false— the original 404-fallback behaviour is unchanged. - Reserved paths in
disallowed_redirect_origin_url_paths(/admin,/dev, …) are never redirected. - Site/host scoping still applies: the check runs in controller context and invokes the
updateRedirectionsFilterextension hook, so any multisiteSiteIDnarrowing works the same as in fallback mode. - Force mode queries
RedirectionFromRelativeURLon every request; it's indexed on the model — rundev/buildafter upgrading.
Usage Examples
Example 1: Redirect Old Page to New Page
$redirector = RedirectionPage::create([ 'Title' => 'Old About Page', 'URLSegment' => 'old-about' ]); $redirector->write(); $redirector->RedirectLink()->LinkType = 'sitetree'; $redirector->RedirectLink()->SiteTreeID = $newAboutPage->ID; $redirector->RedirectLink()->write(); $redirector->publishRecursive();
Example 2: Redirect to External Site
$redirector = RedirectionPage::create([ 'Title' => 'External Resource', 'URLSegment' => 'external-resource' ]); $redirector->write(); $redirector->RedirectLink()->LinkType = 'external'; $redirector->RedirectLink()->ExternalURL = 'https://external-site.com/resource'; $redirector->RedirectLink()->write(); $redirector->publishRecursive();
Example 3: Redirect to File Download
$redirector = RedirectionPage::create([ 'Title' => 'Download Brochure', 'URLSegment' => 'brochure' ]); $redirector->write(); $redirector->RedirectLink()->LinkType = 'file'; $redirector->RedirectLink()->FileID = $brochureFile->ID; $redirector->RedirectLink()->write(); $redirector->publishRecursive();
Example 4: Standalone Redirect
$redirect = Redirection::create([ 'FromURL' => '/old-blog/2020/article', 'StatusCode' => 301 ]); $redirect->write(); $redirect->RedirectLink()->LinkType = 'sitetree'; $redirect->RedirectLink()->SiteTreeID = $newArticlePage->ID; $redirect->RedirectLink()->write();
Admin Interface
Redirections can be managed through the CMS:
- Navigate to the Redirections admin
- Add new redirections
- Set source URL and target link
- Choose HTTP status code
- Save
Migration from RedirectorPage
To migrate existing RedirectorPage instances:
use SilverStripe\CMS\Model\RedirectorPage as CoreRedirectorPage; use Fromholdio\SuperLinkerRedirection\Pages\RedirectionPage; // Get all core redirector pages $oldRedirectors = CoreRedirectorPage::get(); foreach ($oldRedirectors as $old) { $new = RedirectionPage::create([ 'Title' => $old->Title, 'URLSegment' => $old->URLSegment, 'ParentID' => $old->ParentID ]); $new->write(); // Migrate redirect target if ($old->RedirectionType === 'Internal') { $new->RedirectLink()->LinkType = 'sitetree'; $new->RedirectLink()->SiteTreeID = $old->LinkToID; } else { $new->RedirectLink()->LinkType = 'external'; $new->RedirectLink()->ExternalURL = $old->ExternalURL; } $new->RedirectLink()->write(); $new->publishRecursive(); $old->doArchive(); }
Known Issues & Todos
- Validation improvements needed
- File has-many redirects field
- Site tree has-many redirects field improvements
- Proper i18n/translations
- Link tracking/syncing
Documentation
For complete SuperLinker documentation, see:
License
BSD-3-Clause
Support
fromholdio/silverstripe-superlinker-redirection 适用场景与选型建议
fromholdio/silverstripe-superlinker-redirection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.27k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「link」 「silverstripe」 「redirection」 「redirects」 「superlinker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fromholdio/silverstripe-superlinker-redirection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fromholdio/silverstripe-superlinker-redirection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fromholdio/silverstripe-superlinker-redirection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This module allows both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling.
A couple of handy form fields and objects for managing external and internal links on DataObjects
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
Custom links on your sidebar for Laravel Nova.
Set Links with a specific language parameter
This package provides an Database Redirector and Simple Admin Backend for: https://github.com/spatie/laravel-missing-page-redirector
统计信息
- 总下载量: 1.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-07-19