Website in wrong default language after flushing cache

We run a German online shop (web application: OXID v6) customer in two languages (German (default) and English).
After flushing cache it sometimes happens that the Homepage is in English on default. That happens if the first user, uses English as website language, and calls the homepage without language prefix like www.domain.tld.

We tried several ways to deal with it like:

define('BASE_URL_SECURE', strtolower('https://www.' . str_replace('www.', '', $_SERVER['SERVER_NAME'])));

// Cloudflare: FORCE EN
$iCookieLang = isset($_COOKIE['language']) ? (int) $_COOKIE['language'] : 0;
$iCookieLangId = isset($_COOKIE['lang']) ? (int) $_COOKIE['lang'] : 0;
$sRequestUri = isset($_SERVER['REQUEST_URI']) ? strtolower( trim($_SERVER['REQUEST_URI']) ) : FALSE;
$sClassName = isset($_GET['cl']) ? strtolower( trim($_GET['cl']) ) : FALSE;
$iLangId = isset($_GET['lang']) ? (int) $_GET['lang'] : 0;

if (
            ($iCookieLang == 1)
            || ($iCookieLangId == 1)
        && (
            ($sRequestUri == "/")
            || ($sRequestUri == "/index.php")
    || (
        ($sClassName == 'start')
        && ($iLangId == 1)
) {
	header('Location: ' . BASE_URL_SECURE . '/en/');

But it does not help.

Does anyone have an idea how to fix that issue?

Flushing which cache? By default, Cloudflare does not cache page content. Do you have a Page Rule set to “Cache Everything”?

We have a cronjob which flushs the cache via Cloudflare API every day at midnight.

And yes we have a “Cache Everything” page rule.

None of your script is going to help if that page is already in Cloudflare’s cache in some other language. It looks like you’re setting a redirect header for that page if the user has a specific Language cookie. And Cloudflare will cache that page along with that header.

Since it looks like you’re setting cookies, can you set a unique cookie for English (or non-German) users? And then you can user a Worker to Bypass Cache on Cookie (or if on Business Plan, it’s built in as a Page Rule feature). Otherwise, you’ll have to add a Page Rule earlier to Bypass cache for just the home page.

1 Like

Yes, I figured that too. :joy: That’s why I’m looking for support.

Just to make sure. - Yes, we are using cookies and I could probably that a certain cookie for non-german but can’t I use the value of the cookie for Bypass on Cookie page rules?

If you’re on a Business plan, or just using the pmeenan script, it’s not the value of the cookie, but just the existence of a cookie by that name. Set the cookie for a different behavior, or don’t cookie for the other behavior.

Thanks for quick support but how should I setup the page rule? So, that German (www.domain.tld) and English (www.domain.tld/en/) both is cached.
And we are using pro plan.

You can’t cache www.domain.tld/ (just the home page) if it’s going to include the redirect header to /en/ for English users.

I don’t understand how the Cookie is set/read. But, speaking of Workers, some scripting there might handle this for you. Here’s an A/B script that uses cookies:

Someone recently set up a page of Cloudflare resources that may include some potential solutions. Maybe @judge or @domjh remember.

1 Like

:thinking: …

@sdayman, would you be meaning:

Or am I thinking of something different?

1 Like

That’s the one! Thanks!

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.