Michkael Posted March 14, 2019 Posted March 14, 2019 Good day, I have recently added a second language to my website and damn... processwire and its module are priceless! When I tried to automatically redirect the people to their set-up browser language, I encountered a problem with the metadata on linkedin. The error on linkedin was saying that the page was redirected in loop and hence they were not posting the metadata. The following code was right after the </header> in my _head.inc: <?php if(!$session->get('setLang')) { if(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) != 'en') { $session->set('setLang','2'); $url = $page->localUrl('Italiano'); $session->redirect($url); } $session->set('setLang','1'); } ?> When I remove it, it works fine. Do you have any idea on how to obtain the same result, avoiding redirect loops problems? Thank you very much. Michael
Autofahrn Posted March 14, 2019 Posted March 14, 2019 Well, if you see your customer uses a french (or any other country except english) browser, you detect its not english and redirect to italian. Since the browser does not change, you again detect its not english and redirect...
Michkael Posted March 14, 2019 Author Posted March 14, 2019 if(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) != 'en') { This line does not care about the region? Just about the set language, right? If en is the default language, should I somehow change the code?
Autofahrn Posted March 15, 2019 Posted March 15, 2019 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language That field is about the language "the client is able to understand, and which locale variant is preferred". It has nothing to to with the reqion. 15 hours ago, Michkael said: If en is the default language, should I somehow change the code? At least the code should not redetect depending on a decision which does not depend on the redirection. So code is probably something like: if preferredLanguage is not sessionLanguage and installedLanguages(preferredLanguage) exists then redirectSession(preferredLanguage)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now