liquidbcn/craftcms-language-redirect
最新稳定版本:2.0.0-beta.1
Composer 安装命令:
composer require liquidbcn/craftcms-language-redirect
包简介
Simple language redirector based on browser preferences
README 文档
README
Redirects users to localized URLs based on browser language preferences. When a user visits your site's root path (/), the plugin detects their browser language and redirects them to the appropriate localized URL.
Requirements
- Craft CMS 5.0.0 or later
- PHP 8.2 or later
Installation
composer require liquidbcn/craftcms-language-redirect
Then go to Settings → Plugins and click "Install".
Configuration
Option 1: Control Panel (recommended)
Go to Settings → Plugins → Language Redirect and configure:
- Default Language: Fallback locale if browser language isn't in your URL list (e.g.,
en-GB) - Language URLs: Map locale codes to your site URLs
Option 2: Config file
Create config/language-redirect.php:
<?php return [ 'defaultLanguage' => 'en-GB', 'urls' => [ 'ca' => '/ca/', 'ca-ES' => '/ca/', 'es' => '/es/', 'es-ES' => '/es/', 'en-GB' => '/en/', 'en-US' => '/en/', 'en' => '/en/', ], ];
Config file settings take precedence over Control Panel settings.
How it works
- User visits your site root (
/) - Plugin reads the
Accept-Languageheader from the browser - Matches against your configured locale mappings
- Performs a 301 redirect to the corresponding URL
The plugin only triggers on GET and HEAD requests to the root path.
License
MIT
Developed by Liquid Studio
统计信息
- 总下载量: 599
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-11-14