PHPackages                             andersundsehr/geo\_redirect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. andersundsehr/geo\_redirect

ActiveTypo3-cms-extension[Localization &amp; i18n](/categories/localization)

andersundsehr/geo\_redirect
===========================

Redirect users based on browser language and ip country to the right language version of the website

2.0.0(2mo ago)06.3k↑830.8%1GPL-2.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Nov 3Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/andersundsehr/geo_redirect)[ Packagist](https://packagist.org/packages/andersundsehr/geo_redirect)[ Docs](https://github.com/andersundsehr/geo_redirect)[ RSS](/packages/andersundsehr-geo-redirect/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (23)Versions (15)Used By (0)

geo\_redirect 🌍➡️
=================

[](#geo_redirect-️)

This extension redirect users based on browser language and ip country to the right language version of the website.

Installation
------------

[](#installation)

```
composer require andersundsehr/geo_redirect
```

Go to the TYPO3 Extension Settings and configure as you need.

`!!!` If you want to use the ip to Country detection with the mmdb file you should add your `maxmindLicenseKey` (see Extension Settings).
Get your key here:

Features
--------

[](#features)

- Redirect domain root to detected language
- Redirect sys\_redirect to detected language (TYPO3 =&gt; v12 only)

How it works
------------

[](#how-it-works)

This extension uses the user's Accept-Language header and the country derived from the IP address to find the correct language version of the site.
For IP to Country there are mutliple Implementatinos.
If you use Cloudflare or Sucuri, the extension will use the header that is set by the service.
If you set a `maxmindLicenseKey` in the extension settings, the extension will use the mmdb file from maxmind.com.
Otherwise it will ignore the request origin country. And just use the Accept-Language header.

### Options

[](#options)

- `ipCountryIsMoreImportantThanLanguage`: If it is more important that the user gets the content for his country than that he gets content for his languages, then turn this option on.
- `maxmindLicenseKey`: Maxmind.com License Key: if you want to use the mmdb file you should add the license key ()

### Disable for language

[](#disable-for-language)

By default the extension will try to redirect the user to the correct language version of the site. You can disable this for a specific language by adding the following configuration to your `config.yaml` file:

```
languages:
  - # Choose the language you want to disable the geo redirect for
    andersundsehr:
      geo_redirect:
        enabled: false
```

### mmdb file

[](#mmdb-file)

The mmdb file is downloaded from maxmind.com and is updated *every 5 weeks* automatically. If you always want the best performance for your users,
you should add the `typo3 geo-redirect:update-up-database` command to run every month (4 weeks).

### Debugging

[](#debugging)

If you request the domain with this path: `/geo_redirect/debug` you will be given a detailed explenation what language was detected.

### sys\_redirect based on siteLanguage

[](#sys_redirect-based-on-sitelanguage)

This feature makes it possible to redirect the user to a specific page based on the siteLanguage.
You don't need to configure anything, for this to work.
All sys\_redirect records that use a t3://page?uid= link are automatically redirected to the right language version of the page.
(if no \_language= is defined in the redirect)

Extending functionality
-----------------------

[](#extending-functionality)

### PHP Api

[](#php-api)

get the ip country for the current request:

```
class MyClass {
    // inject the IpCountryLocatorInterface using constructor DI
    public __construct(
        protected readonly IpCountryLocatorInterface $ipCountryLocator
    ) {
    }

    // retrieve the country from the request
    public function getIpCountry(): ?string {
        return $this->ipCountryLocator->getIpCountry();
    }
}
```

get the detected language:

```
$siteLanguage = GeneralUtility::makeInstance(SiteLanguageFinderService::class)->findByRequest($request);
// or if you don't have a request object: (in cli the request object is required)
$siteLanguage = GeneralUtility::makeInstance(SiteLanguageFinderService::class)->findByRequest();
// the siteLanguage is never null, because it will always return the default language
```

### custom redirect definition

[](#custom-redirect-definition)

if you want a different redirect definition, you can use the `\AUS\GeoRedirect\Dto\BeforeSiteLanguageFinderEvent` to get all relevant Information and set the `siteLanguage` and `redirectUrl` yourself.

```
