0

Boost works on every page, but it doesn't work on pages with Google Analytics variable in the URL. For example, http://stratton.wanderlustfestival.com/?__utma=1.485948833.1348167330.1348796515.1348837057.31&__utmb=1.3.9.1348837058695&__utmc=1&__utmx=-&__utmz=1.1348167330.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)&__utmv=-&__utmk=172983075 doesn't show <!-- Page cached by Boost @ 2012-09-27 16:23:18, expires @ 2012-09-28 04:23:18 --> while http://stratton.wanderlustfestival.com does.

2 Answers 2

5

Boost saves the page cache in a file named after the page + the query string, the limit on the length of a filename is 255 in Linux so for pages with very long name/query string combinations caching will fail.

This should show up as an error in the Drupal log and if it does the solution is edit the .htaccess: Find the comment "Caching for anonymous users", after this you'll find a line "RewriteRule .* - [S=4]", replace this line with the following code:

RewriteRule .* - [S=6]

# If the page/query string combination is not over 255 characters, skip the following 2 rewrites
RewriteCond %{QUERY_STRING} "utm_campaign"
RewriteCond %{QUERY_STRING} "utm_medium"
RewriteCond %{REQUEST_URI}_%{QUERY_STRING} ^(.*\/)([^\/\n]{0,255})$
RewriteRule .* - [S=2]

# Custom Campaign Query
# Create file if not already boosted
# One campaign item is lost for file creation.
ReWriteCond %{QUERY_STRING} "utm_campaign"
ReWriteCond %{QUERY_STRING} "utm_medium"
RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{HTTP_HOST}%{REQUEST_URI}_\.html !-s
ReWriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}? [L,T=text/html]

# Boosted file for campaign (now with query string).
ReWriteCond %{QUERY_STRING} "utm_campaign"
ReWriteCond %{QUERY_STRING} "utm_medium"
RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{HTTP_HOST}%{REQUEST_URI}_\.html -s
RewriteRule .* cache/normal/%{HTTP_HOST}%{REQUEST_URI}_\.html [L,T=text/html]

This makes sure that if the page/analytics query string combination is too long it will cache the page without query string instead, the first request will be redirected to the page without the Analytics query string, the next request will be served from cache and the query string will stay intact.

Note that this code is aimed at long url's with Google Analytics tracking variables only but can be (and possibly should be) rewritten so it can be used universally.

0

I ran into this issue in June 2016 after installing Boost on fairly busy site. Note that there are two related issues when requests exceed 255 characters: (1) Boost generates an error in the log and doesn't finish creating a cache file and (2) "orphaned" temporary files will appear in the boost cache (files beginning with "boost").

After studying the nice answer by @midnightMotion a while, I decided to try a fix in .htaccess

Using Boost 7.x-1.1, this is what I have added:

# If the page/query string <= 255 characters, skip following 2 rewrites
RewriteCond %{REQUEST_URI}_%{QUERY_STRING} ^(.*\/)([^\/\n]{0,255})$
RewriteRule .* - [S=2]

# No cache file - strip query and redirect to create
# One campaign item is lost for file creation.
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_\.html !-s
RewriteRule ^(.*)$ http%{ENV:protossl}://%{HTTP_HOST}%{REQUEST_URI}? [L,T=text/html]

# Cache file exists - use it
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_\.html -s
RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_\.html [L,T=text/html]

Note syntax is adjusted slightly for a newer version of boost. I also adjusted the "skip" after the intial boost rule to s=4 to skip the new stuff above when boost isn't triggered.

This appears to have fixed the errors in log, the orphaned boost temp files, and the general problem of long uri + queries not getting a cache.

I'm not an htaccess expert my any means, so please jump in with suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.