PHP Classes

How Can PHP Detect the Browser Language and Redirect to the Correct Language Page Using the Package Site Language Redirection: Redirect TYPO3 users to site of their language

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-06-09 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
site-language-redire 1.0MIT/X Consortium ...7Localization, HTTP, Content management, P...
Description 

Author

This package can redirect TYPO3 users to a site of their language.

It provides a middleware class to be used with the TYPO3 content management system that can check the HTTP request Accept-Language header to determine the current request user preferred language.

The middleware class can redirect accesses of users to different URL if there is another page for the same content that is available in the current page that is in the user preferred language.

Picture of Harald Atteneder
Name: Harald Atteneder <contact>
Classes: 1 package by
Country: Austria Austria

Instructions

Documentation

TYPO3 Site Language Redirection

PSR-15 middleware to redirect user to correct site language.

  • Language detection is based on HTTP headers (browser language) or IP address.
  • When the user switches the language, a cookie gets set to save the new language as preferred language.

How it works

Example of how the extensions determines the site to redirect to via HTTP headers:

If Accept-Language is en-US,de-AT it looks for sites with an hreflang of en-US. If there is no match it then looks for en. If there is still no match it repeats the same logic with de-AT and so on.

Installation

Install via Extension Manager or composer.

composer require urbantrout/site-language-redirection

Enable IP address based redirects

  1. Update the GeoIP2 database file for IP address based redirects via CLI or Scheduler. CLI* `./vendor/bin/typo3 sitelanguageredirection:updatedb` Scheduler* Create new task of class Excute console commands and set Schedulable Command to sitelanguageredirection:updatedb Settings of new scheduler task Use this option to periodically update your database file.

    This step creates a file under `\TYPO3\CMS\Core\Core\Environment::getVarPath() . '/sitelanguageredirection/'` with all the geolocation information. Note: This does not alter your SQL database.

  2. Update the preferred method in your site configuration in the tab Site Language Redirection. Defaults to HTTP headers.  
    Screenshot of Site Language Redirection tab in site configuration  
    Changing this value to IP address updates `config/sites/<sitename>/config.yaml` and adds the following line of code:  
    SiteLanguageRedirectionMethod: 2
    

Configure Language Fallbacks

This feature adds the possibility to define fallback languages. So for instance, if there's no italian version of the website, redirect to english version, and so on.

Site configuration would look like this with optional SiteLanguageRedirectionFallbacks:

SiteLanguageRedirectionMethod: 1
SiteLanguageRedirectionFallbacks:
  fr: 'en'
  it: 'en'

  Files folder image Files (23)  
File Role Description
Files folder imageClasses (2 directories)
Files folder imageConfiguration (2 files, 1 directory)
Files folder imageDocumentation (8 files, 1 directory)
Files folder imageResources (1 directory)
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file ext_emconf.php Aux. Configuration script
Accessible without login Plain text file Index.rst Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (23)  /  Classes  
File Role Description
Files folder imageCommand (1 file)
Files folder imageMiddleware (1 file)

  Files folder image Files (23)  /  Classes  /  Command  
File Role Description
  Plain text file UpdateDB.php Class Class source

  Files folder image Files (23)  /  Classes  /  Middleware  
File Role Description
  Plain text file RedirectionMiddleware.php Class Class source

  Files folder image Files (23)  /  Configuration  
File Role Description
Files folder imageSiteConfiguration (1 directory)
  Plain text file Commands.php Class Class source
  Plain text file RequestMiddlewares.php Class Class source

  Files folder image Files (23)  /  Configuration  /  SiteConfiguration  
File Role Description
Files folder imageOverrides (1 file)

  Files folder image Files (23)  /  Configuration  /  SiteConfiguration  /  Overrides  
File Role Description
  Accessible without login Plain text file sites.php Aux. Configuration script

  Files folder image Files (23)  /  Documentation  
File Role Description
Files folder imageImages (2 files)
  Accessible without login Plain text file .editorconfig Data Auxiliary data
  Accessible without login Plain text file Configuration.rst Data Auxiliary data
  Accessible without login Plain text file Includes.txt Doc. Documentation
  Accessible without login Plain text file Index.rst Data Auxiliary data
  Accessible without login Plain text file Installation.rst Data Auxiliary data
  Accessible without login Plain text file Introduction.rst Data Auxiliary data
  Accessible without login Plain text file Settings.cfg Data Auxiliary data
  Accessible without login Plain text file Sitemap.rst Data Auxiliary data

  Files folder image Files (23)  /  Documentation  /  Images  
File Role Description
  Accessible without login Image file scheduler.png Icon Icon image
  Accessible without login Image file site-config.png Icon Icon image

  Files folder image Files (23)  /  Resources  
File Role Description
Files folder imagePublic (1 directory)

  Files folder image Files (23)  /  Resources  /  Public  
File Role Description
Files folder imageIcons (1 file)

  Files folder image Files (23)  /  Resources  /  Public  /  Icons  
File Role Description
  Accessible without login Plain text file Extension.svg Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0