jorisnoo / statamic-locale-redirect
A Statamic addon that redirects visitors to the locale-specific home route.
Package info
github.com/jorisnoo/statamic-locale-redirect
pkg:composer/jorisnoo/statamic-locale-redirect
Requires
- php: ^8.2
- statamic/cms: ^5.0 || ^6.0
Requires (Dev)
- orchestra/testbench: ^9.0 || ^10.0
- pestphp/pest: ^3.8
- pestphp/pest-plugin-laravel: ^3.2
- phpunit/phpunit: ^11.0
README
A Statamic addon 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 Statamic 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+
- Statamic 5 or 6
Installation
composer require noordermeer/statamic-locale-redirect
That's it. The addon registers itself automatically via Laravel's package discovery.
How It Works
When a visitor hits your site's root URL (/), the middleware:
- Reads the
Accept-Languageheader from the browser - Fetches all configured Statamic 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 default site's URL (or a configured fallback). Query parameters are preserved through the redirect.
Configuration
The addon works out of the box with no configuration. To customize behavior, publish the config file:
php artisan vendor:publish --tag=locale-redirect
This creates config/statamic/locale-redirect.php:
return [ 'exclude' => [], 'only' => [], ];
Exclude Locales
Prevent specific locales from being redirect targets:
'exclude' => ['de', 'it'],
Restrict to Specific Locales
Only allow redirection to specific locales. When set, only takes precedence over exclude:
'only' => ['en', 'fr'],
Testing
./vendor/bin/phpunit
License
The MIT License (MIT). Please see LICENSE for more information.