statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Strange result for full measure caching with localization #2294

Open jimblue opened 5 years ago

jimblue commented 5 years ago

I'm following the doc to combined full measure caching combined with localization:

"When using full measure caching combined with localization, you may need to save the html files within each appropriate locale’s webroot. You may do this by placing an array in the file locations with the various locales."

static_caching_file_path:
en: static
fr: fr/static

With the above configuration and using Valet, the generated html files can be found:

- in `/static` for **EN** locale 
- in `/fr/static/fr` for **FR** locale 

This is a strange path for FR don't you think? It should be fr/static as previously setup in Statamic settings nope?

This is probably why the cache is rendered again and again for FR locale! So I've try to change the settings to a simple path, not an array:

static_caching_file_path: static

Now the generated html files can be found:

That make more sens... and.... it's working!!!

Kind of strange don't you think? This is the opposite of what the doc say...

So what's wrong... The documentation or something else?

wanze commented 5 years ago

It seems like the docs are wrong about this: The HTML files for each locale are already written to locale-subfolders inside the configured static_caching_file_path. However, if each locale has its own subfolder inside the document root, it is necessary to tweak the redirect rule for non-primary locales in order to make it work:

RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteCond %{REQUEST_METHOD} GET

# The below rule works for the primary locale.
RewriteRule .* static/%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]

# The below rule works for non-primary locales: The static folder is one level above now.
RewriteRule .* ../static/%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]