eZ Community » Forums » eZ Publish 5 Platform » How to change siteaccess based on...

How to change siteaccess based on browser language

How to change siteaccess based on browser language

Friday 07 March 2014 10:36:05 pm - 2 replies


Which is the best way to change the siteaccess based on the browser language?

I tried, without luck, subscribing to the onKernelRequest event and then using this code

$siteaccess = new SiteAccess('eng');
$this->container->get('request')->attributes->set('siteaccess', $siteaccess);


Modified on Friday 07 March 2014 10:36:42 pm by Gabriele Perego

Saturday 08 March 2014 3:50:52 am

It might be good to consider using the server (these notes are for Apache) to route the requests based on the Accept-Language header.
You may be able to use following code to route visitors to a default siteaccess.  The first condition is checking for the initial entry to the site.  If the visitor is visiting the home page, you may assume they are starting their session and route them to a siteaccess based on the Accept-Language header.  Offering links to different languages would allow visitors to change siteaccesses.

RewriteCond %{REQUEST_URI} ^http://example.com$ [NC]
RewriteCond %{HTTP:Accept-Language}  en [NC]
RewriteRule .* http://example.com/eng [L]

(not tested)
Reference: https://www.w3.org/International/questions/qa-accept-lang-locales

You may also be able to use content negotiation: http://httpd.apache.org/docs/current/content-negotiation.html

Modified on Saturday 08 March 2014 3:52:27 am by Betsy Gamrat

Tuesday 11 March 2014 4:27:58 pm

Thanks Betsy, following your approach probably I can also use the X-Siteaccess header as stated here https://confluence.ez.no/display/EZP/Siteaccess+Matching

Any hint instead for the "Symfony" approach?

Thanks, Gabriele


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from