I’ve just spend the best part of a day messing around with a thoroughly annoying issue on a WP Powered site.

The brief was simple – add a pop-up which prompts the user to complete a survey, if the user declines or accepts store this action in a cookie so the pop-up never appears again.

Easy right? Well yes. I’ve done this a few times before, no problem.

This time however there was a problem. The cookie just wouldn’t ‘stick’. By that I mean it was as if the pages on the site were just ignoring it. The pop-up was looping round, poping up all over the place no matter what the user had selected.

I re-wrote the code 3 times over 2 days – still the same issue. I tried everything from disabling all my plugins trying the site on multiple connections and different computers/browsers. All the same.

I knew the issue was something to do with the site cache. But nothing I did worked. Even with no plugins and no permalinks the site gave me no clue as to where I was going wrong.

And then I opend my .htaccess file.

Turns out a couple of weeks before I had left some code in the file from when I had been messing around configureing WP Cache

Something like this:

—————–.htaccess—————–
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{QUERY_STRING} !.*attachment_id=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
—————–.htaccess—————–

# BEGIN supercache

AddEncoding gzip .gz
AddType text/html .gz


SetEnvIfNoCase Request_URI \.gz$ no-gzip


Header set Cache-Control ‘max-age=300, must-revalidate’


ExpiresActive On
ExpiresByType text/html A300

# END supercache

The above code was the problem. When I worked this out and removed it, the site worked file. Rather than being happy, I was pissed off. I mean, hours and hours of work. At one point I smacked down on my keyboard so hard some of the keys came off!

So, if you’ve ever messed around with WP Cache and your .htaccess file, please remember to remove all the settings when you are done. It will save you a lot of pain.