jorisnoo/craft-locale-redirect
Composer 安装命令:
composer require jorisnoo/craft-locale-redirect
包简介
Browser locale detection and redirect for Craft CMS
README 文档
README
A Craft CMS module that automatically redirects visitors from / to their locale-specific home route based on their browser language preferences.
Features
- Detects the visitor's preferred language from the
Accept-Languageheader - Matches it against your Craft multi-site locales
- Redirects from
/to the best-matching locale home URL (e.g./en,/fr,/de) - Preserves query parameters through the redirect
- Configurable locale exclusions and restrictions
- Zero configuration required for basic usage
Requirements
- PHP 8.2+
- Craft CMS 5
Installation
composer require jorisnoo/craft-locale-redirect
Then register the module in your config/app.php:
return [ 'modules' => [ 'locale-redirect' => \Noo\CraftLocaleRedirect\Module::class, ], 'bootstrap' => ['locale-redirect'], ];
How It Works
When a visitor hits your site's root URL (/), the module:
- Reads the
Accept-Languageheader from the browser - Fetches all configured Craft site locales and their URLs
- Finds the best match between browser preferences and available locales
- Issues a
302redirect to the matched locale's home URL
If no match is found, the visitor is redirected to the primary site's URL (or a configured fallback). Query parameters are preserved through the redirect.
Configuration
The module works out of the box with no configuration. To customize behavior, create a config/locale-redirect.php file in your Craft project:
<?php return [ 'excludeSites' => [], 'exclude' => [], 'only' => [], 'fallback' => null, ];
Exclude Sites
Prevent the redirect from triggering on specific sites (by handle). Useful when locale-specific sites already have their own prefix and shouldn't redirect further:
'excludeSites' => ['english', 'german'],
Exclude Locales
Prevent specific locales from being redirect targets:
'exclude' => ['de', 'it'],
Restrict to Specific Locales
Only allow redirection to specific locales. Takes precedence over exclude when both are set:
'only' => ['en', 'fr'],
Fallback URL
The URL to redirect to when no browser locale matches. Defaults to the primary site URL:
'fallback' => '/en',
Branching and Versioning
This package follows Semantic Versioning. Only Craft 5 is supported.
License
The MIT License (MIT). Please see LICENSE for more information.
jorisnoo/craft-locale-redirect 适用场景与选型建议
jorisnoo/craft-locale-redirect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 311 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「cms」 「locale」 「redirect」 「language」 「Craft」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jorisnoo/craft-locale-redirect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jorisnoo/craft-locale-redirect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jorisnoo/craft-locale-redirect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
A custom URL rule class for Yii 2 which allows to create translated URL rules
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
统计信息
- 总下载量: 311
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-18