liquidbcn/craftcms-language-redirect 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

  1. User visits your site root (/)
  2. Plugin reads the Accept-Language header from the browser
  3. Matches against your configured locale mappings
  4. 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

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2022-11-14