site access doesn't appear in url

27 views Asked by At

I'm struggling with following issue : I want to redirect the user to a specific site access when he comes to the home page My solution seems to work, but the new site access I'm redirecting the user to doesn't appear in the url

I am using ezplatform version 2.5

Here is the current workflow:

  1. user comes to the home page
  2. we determine the site access for the user (for example it-it)
  3. user is redirected to determined site access
  4. I see that the has been redirected to correct site access (language has changed)

issue : in the browser's address bar, the url is still my-site.com instead of my-site.com/it-it

To match against the desired site access, I use a custom matcher which extends eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Map :

public function setRequest(SimplifiedRequest $request)
    {
        if (!$this->key && in_array($request->pathinfo, Constants::LANDING_PAGES)) {
            $language = $this->getBrowserLanguage();
            $countryCode = $this->getCountryCodeByIP();

            // read config from ezplatform.yml file
            $config = $this->getConfig();

            // check if country in one of the fallback countries
            if (array_key_exists($countryCode, Constants::COUNTRY_FALLBACKS))
            {
                $countryCode = Constants::COUNTRY_FALLBACKS[$countryCode];
            }

            // switch to int market if countryCode doesn't exist in site accesses
            if (!$this->isCountryInAvailableSiteaccesses($countryCode, $config))
            {
                $countryCode = 'int';
            }

            // use english as fallback language
            if (!$this->isLanguageAvailableInMarket($language, $countryCode, $config))
            {
                $language = 'en';
            }
            $siteAccess = $language. '-'.$countryCode;

            $this->setMapKey($siteAccess);
        }

        parent::setRequest($request);
    }

My ezplatform.yml looks like that :

ezpublish:
    siteaccess:
        default_siteaccess: de-de
        list:
            - admin
            - de-de
            - it-it
           #... plenty of other site accesses

        groups:
            admin_group:
                - admin
            frontend_group:
                - de-de
                - it-it
               #... all the other site accesses
            
        match:
            \CustomerBundle\SiteAccessMatcher\CustomMatcher:
                # xx-xx : language-country
                de-de: de-de
                it-it: it-it
                

    system:
        frontend_group:
#            translation_siteaccesses:
#                - deu-de
            design: customer
            content:
                tree_root:
                    location_id: 167
                    excluded_uri_prefixes: [ /media, /images ]

        de-de:
            languages:
                - ger-DE
        it-it:
            languages:
                - ita-IT
        #... all the other site accesses 

        admin_group:
            languages:
                - eng-GB
                - ger-DE
                - fre-FR
        admin:
            languages:
                - ger-DE
                - eng-GB
            content_tree_module:
                contextual_tree_root_location_ids:
                    - 2 # Home (Content structure)
                    - 5 # Users
                    - 43 # Media
                    - 48 # Setup
            subtree_paths:
                content: /1/2/
                media: /1/43/```
0

There are 0 answers