Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Cloudflare GEO Redirect

Cloudflare GEO Redirect

I have a chameleon rule setup that redirects all new york visitors to a /new-york url.  The redirect works fine, but whenever I enable Cloudflare the redirect stops working after a while and when I purge the Cloudflare cache it starts working again.  So I guess somehow it is caching something incorrectly.  Do you have any suggestions on how I can resolve this?  Is there a way for me to prevent the caching of chameleon rule?

Thanks,

Sima

Sima
SIMA
Junior Modder
ranks
useravatar
Offline
21 Posts
User info in posts
Administrator has disabled public posting

Re: Cloudflare GEO Redirect

Hi Sima,

Do you think this might apply to your situation:

https://support.cloudflare.com/hc/en-us … loudflare-

Perhaps in the Succeed Action where you do the redirect, you could use the PHP box to add an HTML header, perhaps like this: (I haven't tried this)

  //set headers to NOT cache a page
  header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
  header("Pragma: no-cache"); //HTTP 1.0
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Please let me know how you get on smile

Best regards
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Cloudflare GEO Redirect

Just thinking about this some more, if for a certain URL, SOMETIMES it will redirect, and SOMETIMES it will show a particular page, then you need to ensure that Cloudflare doesn't cache the normal HTML page. Otherwise, all your New York users are likely to see the cached HTML rather than being redirected.

So, you might need to tell Cloudflare NEVER to cache that particular URL. Perhaps that's the home page? If so, you're going to have to choose what's more important: that Cloudflare caches the page, or that Chameleon gets the chance to check the GeoIP and do a redirect. Obviously, if the HTML of the page is cached at Cloudflare, then your server doesn't receive the page request at all, so Chameleon doesn't get a chance to test any conditions.

If you really want the best of both worlds, you could try to combine the 2 approaches by doing the redirect with some dynamic Javascript called from the page.

e.g. on your front page you could get it to load a JS script from your site e.g. mysite.com/myscript.js
Use Chameleon to detect the JS URL mysite.com/myscript.js, and if found and if GeoIP is from New York, then use a PHP script in the Succeed Action to add a redirect as well as adding the nocache headers.

In this way, the actual page can still be cached at Cloudflare, and the client will still call the little JS script from your server (not cached). And it's that script that does the redirect if necessary.

Hope that helps

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Cloudflare GEO Redirect

Thanks for the great feedback.  I am going to think about it and experiment.

As far as chameleon goes, how is it included in the pages of Joomla? Is it an include file?

Sima
SIMA
Junior Modder
ranks
useravatar
Offline
21 Posts
User info in posts
Administrator has disabled public posting

Re: Cloudflare GEO Redirect

Hi Sima,

Joomla has a system of plugins that allow you to insert code into various stages of the system. Chameleon inserts itself pretty early in the process, before the exact page is processed, and allows you to make a number of changes to how the system works. Further internal plugins operate after the page is rendered, and allow Chameleon to make changes to the final output, based on conditions that are determined earlier in the process.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
7
User Info:
 
Total Users:
5387
Newest User:
tomasini8h
Members Online:
1
Guests Online:
115

Online: 
tomasini8h

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked