Conditional redirect settings

Hello, hope you would be able to help with my new challenge

We have:
WP site hosted with NameCheap
W3TC caches on WP level
Polylang plugin driving 3 language locales (EN/UA/RU, whereby EN is a primary one)
The site is also on free Cloudflare (Caching Level Standard)

By the new law, all sites in UA should open UA locale by default (even if browser locale is not UA)

The solution I’ve managed to find:
Installed Cloudflare GeoIP Redirect plugin
Set the rule if country = UA, then 307 redirect with query string ?lang=ua (which inefficiently triggers UA locale - it would be better to re-direct to /ua/pagename_ua/)

Result: all works UA version opened in UA and EN version opened in the UK

The issue I faced:
high “speed index” in g-speed report

could you please advise if there is another (better) way of conditional redirect (based on geoIP)?

Thanks

I’ve tried the method described by @michael
here and here

2 issues faced and can’t find the reason / way to resolve:

  1. $1 in Page rule works partially (converting /pagename to /ua/pagename), but then a long delay follows as (?) polylang on the server side recognises the request and adds “_ua” to the pagename
    I’ve tried adding something after $1 (“_ua”, “_ua”), but no luck
    I’m not the most technical person, hope someone could suggest the right syntax

  2. When transform and page rules are disabled the pages work well, but when enabled - they break css

before vs after
Not sure how forwarding breaks css and how to fix this

Any help & advice much appreciated

May I ask did you used and enabled Cloudflare extension by navigating to the W3TC menu → Extensions then selecting Cloudflare?, or maybe you’ve installed a separate official Cloudflare plugin for WordPress? :thinking:

Good, should work fine if you’re seeing the real visitor IP in your access log files / stats :thinking:

Helpful article:

Or, otherwise, configured to present the content language depending to the visitor IP or visitor browser accept language.

Unfortunately, I am not familiar with this plugin.

So you have issue where a plugin does the redirect for a language and also Cloudflare as you have tried to configure it via Cloudflare Transform & Page Rules?
Or you deactivated one of them beacuse of the “conflict”, if I could say it like that.

Aha, sorry, so the CSS is the issue then?

1 Like

yes, I enabled Cloudflare extension in W3TC

currently Polylang presents content based on the visitor browser locale
link

I deactivated GeoIP Redirect plugin before/during experimenting with Cloudflare Transform & Page Rules

correct, broken CSS is a primary issue

lack of syntax knowledge is a secondary one :slight_smile:

@fritex I would like to clarify - the CSS issue appears only when Cloudflare transform and page rules were applied, otherwise even “Cache Everything” works pretty well

Right.

For the 1st issue about long delay …

I wonder if it has to be something related to the origin host maybe to generate that on PHP side?

For the 2nd issue about CSS…

I wonder about your Transform Rule, you could possibly be somehow excluding the URLs to the CSS & JS resources simply by adding if URI path does not contain .css for example, as far as what I understand how it goes by rewriting them and then you get 404 error for them, correct? :thinking:

Nevertheless, we could … check for WordPress cookie (not 100% sure), if it exists, to not to cause another mess once we’re logged into the WP admin dashboard.

But, I am now just thinking, so you’d be using 2 or 3 times, like

something something and URI path does not contain .css
OR
something something and URI path does not contain .js
OR
something something and URI path does not contain .jpg

That way, I think it shouldn’t have effect and the resources should load fine (hopefully) despite being on the different homepage per language, then as they’d point to the correct WordPress directory, including if something is loading from wp-admin for a plugin, or wp-includes, either from wp-contnet/plugins or themes.

I haven’t tried that combination yet, might have to take me a day or two to install the same as you have and try out.

Would be good if you could share, or you already did shared, your Transform Rule(s) and Page Rule(s) so we could adjust them as needed for your case.

1 Like

These are the rules I’m trying to implement

Hi @fritex
Hope you’re doing well.

Any luck with your experiments? Maybe we should consider worker-based approach instead?

Thanks!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.