简体   繁体   中英

Magento Varnish Turpentine punch hole for php redirect

On a Magento installation I have installed Varnish and Turpentine. The caching is working fine but I am having trouble punching a hole for a GeoIP redirect block. This block works correctly on a dev version of the site that does not have varnish installed.

This GeoIP block needs to do a php header location redirect to send the user to the correct language/currency based on their IP. Magento is configured with multiple websites and store views.

Because php header location redirects only work if there is no output on the page I have included my GeoIP block in Magento head block and then set the EsiOptions with a time to live of 0.

<block type="page/html_head" name="head" as="head">
     <block type="geoipswitch/geoIpSwitch" name="geoIpSwitch"> 
          <action method="setEsiOptions">
               <params>
                   <access>private</access>
                   <ttl>0</ttl>
                </params>
            </action>
      </block>
   ...

I am aware that this is not the best place for the caching options but I am trying to reduce the number of possible problems. I have tried using flush events and ajax/esi methods.

<block type="page/html_head" name="head" as="head">
         <block type="geoipswitch/geoIpSwitch" name="geoIpSwitch"> 
              <action method="setEsiOptions">
                   <params>
                       <access>private</access>
                       <ttl>0</ttl>
                       <method>ajax</method>
                    </params>
                </action>
          </block>
       ...

No matter what I try after flushing the cache the first visitor gets redirected correctly and then every visitor after that gets sent to the same site regardless of their IP.

If anyone has any suggestions or help it is greatly appreciated.

Your xml looks fine, and it should have worked...

First of all please make sure that you have flushed Magento's cache storage (layout xmls and blocks may be cached) and you have performed a full varnish purge.

If you have done all these, one thing you can try, is to set scope and flush_events. I am suggesting for you to use page scope and the controller_action_layout_load_before event as flush event:

<action method="setEsiOptions">
    <params>
        <access>private</access>
        <scope>page</scope>
        <method>esi</method>
        <ttl>0</ttl>
        <flush_events>
            <controller_action_layout_load_before/>
        </flush_events>
    </params>
</action>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM