Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: cached pages have different URL

Status Resolved
Add-on / Version Speedy 1.3.0
Severity
EE Version 5.3.2

Francesco Pensabene

Nov 25, 2020

Hello,

just installed speedy, activated static caching.
The problem is that when a page gets cached it changes URL for example :

http://146.59.237.173/dove-siamo/
becomes:
http://146.59.237.173/static/default_site/static/dove-siamo/

this is my .htaccess:

RewriteEngine On
RewriteBase /

#boldminded speedy addon
RewriteCond %{REQUEST_URI} !^/system [NC]
RewriteCond %{QUERY_STRING} !ACT|URL [NC]
RewriteCond %{REQUEST_METHOD} !=POST [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{DOCUMENT_ROOT}/static/default_site/static%{REQUEST_URI}/index\.php -f
RewriteRule ^ /static/default_site/static%{REQUEST_URI}/index\.php [L,QSA]


# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

#1

BoldMinded (Brian)

Can you share screenshots of your “static” folder, including all sub folders. I want to see if the rest of the directory structure was created correctly.

Also, did you try removing the last 2 htaccess blocks? (everything after # Removes index.php from ExpressionEngine URLs)

#2

Francesco Pensabene

with this .htaccess I can only browse home page: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !^/system [NC] RewriteCond %{QUERY_STRING} !ACT|URL [NC] RewriteCond %{REQUEST_METHOD} !=POST [NC] RewriteCond $1 !.(css|js|gif|jpe?g|png) [NC] RewriteCond %{DOCUMENT_ROOT}/static/default_site/static%{REQUEST_URI}/index.php -f RewriteRule ^ /static/default_site/static%{REQUEST_URI}/index.php [L,QSA]
</IfModule>

#3

Francesco Pensabene

so with the .htaccess as above I cannot reach any subfolder url -> i need to put index.php

for example: http://146.59.237.173/contattaci -> gives 404 erro http://146.59.237.173/index.php/contattaci -> this works

Also my server requires forcing query strings so I usually edit the standard EE .htaccess like so:

RewriteRule ^(.*)$ /index.php?/$1 [L]

#4

BoldMinded (Brian)

Can you please share screenshots of your static folder with all the files in it so I can see the directory structure? Honestly there isn’t much I can do if he static folder has the correct files. I know that the example htaccess rules in the docs work, and they’re just examples that aren’t officially supported. So if the static directory contains the correct files than there may be something else causing the issue… any number of things can be causing a problem and possibly unrelated to Speedy.

#5

Francesco Pensabene

I cannot share the directory image right now but I can confirm that the cache files are generated correctly. For me the problem resides in the htaccess rules.

I added the last lines of the standard EE htaccess and now I can browse the website:

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !^/system [NC] RewriteCond %{QUERY_STRING} !ACT|URL [NC] RewriteCond %{REQUEST_METHOD} !=POST [NC] RewriteCond $1 !.(css|js|gif|jpe?g|png) [NC] RewriteCond %{DOCUMENT_ROOT}/static/default_site/static%{REQUEST_URI}/index.php -f RewriteRule ^ /static/default_site/static%{REQUEST_URI}/index.php [L,QSA]

Directs all EE web requests through the site index file

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L] </IfModule>

I don’t have anything strange in place it’s just a new centos/plesk webserver with standard configuration.

#6

BoldMinded (Brian)

Also my server requires forcing query strings so I usually edit the standard EE .htaccess like so: RewriteRule ^(.*)$ /index.php?/$1 [L]

This is kind of what I’m referring to… servers can be wildly different… you may have to experiment with the example htaccess rules to find what works for you. I don’t know if this is correct, b/c I’m not an htaccess expert, but maybe start here:

RewriteRule ^(.*)$ /static/default_site/static%{REQUEST_URI}/index\.php?/$1 [L,QSA]
#7

BoldMinded (Brian)

This is what I have in my local environment, which works with static files or the static using Redis:

RewriteEngine On
RewriteBase "/"

Header set Access-Control-Allow-Origin *

# Speedy Static file driver
RewriteCond %{REQUEST_URI} !^/system [NC]
RewriteCond %{QUERY_STRING} !ACT|URL [NC]
RewriteCond %{REQUEST_METHOD} !=POST [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{DOCUMENT_ROOT}/static/default_site/static%{REQUEST_URI}/index\.php -f
RewriteRule ^ /static/default_site/static%{REQUEST_URI}/index\.php [L,QSA]

# Speedy Redis as Static driver
RewriteCond %{REQUEST_URI} !^/admin.php [NC]
RewriteCond %{QUERY_STRING} !ACT|URL [NC]
RewriteCond %{REQUEST_METHOD} !=POST [NC]
RewriteCond %{REQUEST_URI} !^/~ [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/index_redis_default_site\.php -f
RewriteRule ^(.*)$ index_redis_default_site\.php?%{REQUEST_URI} [L,QSA]

# Do our rewrites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#8

Francesco Pensabene

Ok,

so the last 3 rules are needed by EE to redirect every url through index.php

#9

Francesco Pensabene

The last question… is there a way to prune only one page cache? Is it only possible to delete ALL cached files?

#10

BoldMinded (Brian)

If you click on the magnifying glass you should be able to see and delete individual keys, or re-save the entry and based on your cache busting rules should delete the static file too.

https://www.dropbox.com/s/k4j9u0q9gy4hj5l/ticket-2918-cache-clear.png?dl=0

#11

Francesco Pensabene

Hello Brian,

Now I’m trying to use the fragment caching, I’m working with layouts and I did as stated in the docs i escaped all contents that needs to be replaced in the layout. But I noticed that in the final template I must escape also the {layout:set name=’custom_variable’} othervise I ge an error on the template. is that correct? I couldn’t find anything in the docs

#12

BoldMinded (Brian)

Can you paste in the full template code you’re using so I can replicate it? You can strip out non relevant html tags or channel:entries tags that aren’t important… basically strip the templates down to the bare minimum to make the issue happen, and paste them here.

Btw it’s a holiday weekend in the states, so my response times may be delayed a bit.

#13

BoldMinded (Brian)

Are you still using full page static caching?

#14

Francesco Pensabene

THIS IS THE LAYOUT:

{exp:speedy:fragment key=”layout_generico”} <!doctype html> <html class=”no-js” lang=”it”> <head> <meta charset=”utf-8”> <meta http-equiv=”x-ua-compatible” content=”ie=edge”> <meta name=”viewport” content=”width=device-width, initial-scale=1.0”> <!–*** FAVICON –> <link rel=”apple-touch-icon” sizes=”180x180” href=”/assets/favicon/apple-touch-icon.png”> <link rel=”icon” type=”image/png” sizes=”32x32” href=”/assets/favicon/favicon-32x32.png”> <link rel=”icon” type=”image/png” sizes=”16x16” href=”/assets/favicon/favicon-16x16.png”> <link rel=”manifest” href=”/assets/favicon/site.webmanifest”> <link rel=”mask-icon” href=”/assets/favicon/safari-pinned-tab.svg” color=”#043c6b”> <link rel=”shortcut icon” href=”/assets/favicon/favicon.ico”> <meta name=”msapplication-TileColor” content=”#ffffff”> <meta name=”msapplication-config” content=”/assets/favicon/browserconfig.xml”> <meta name=”theme-color” content=”#ffffff”> <!– STYLES slick css è in app.min.css –> <link rel=”stylesheet” href=”{site_url}assets/foundation-sites/css/app.min.css”> <link rel=”stylesheet” href=”{site_url}assets/foundation-icons/foundation-icons.css”> <link rel=”stylesheet” href=”{site_url}assets/fontawesome-free-5.13.1-web/css/all.min.css”> <!– SEO TAGS –> <title>{exp:speedy:escape}{if layout:title}{layout:title}{if:else}WorldBridge{/if}{/exp:speedy:escape}</title> <meta name=”description” content=”{exp:speedy:escape}{layout:meta_description}{/exp:speedy:escape}”> {if global:env == ‘stage’}<meta name=”robots” content=”noindex”>{/if} {if global:env == ‘local’}<meta name=”robots” content=”noindex”>{/if} <!– SOCIAL TAGS –> <meta property=”og:url” content=”{current_url}” /> <meta property=”og:type” content=”article” /> <meta property=”og:title” content=”{exp:speedy:escape}{if layout:title}{layout:title}{if:else}WorldBridge{/if}{/exp:speedy:escape}” /> <meta property=”og:description” content=”{exp:speedy:escape}{layout:meta_description}{/exp:speedy:escape}” /> <meta property=”og:image” content=”{exp:speedy:escape}{if layout:facebook_image}{layout:facebook_image}{if:else}{site_url}assets/img/facebook-default-images/worldbridge-connecting-cultures.jpg{/if}{/exp:speedy:escape}” /> <meta property=”fb:admins” content=”646368982” /> {if global:env == ‘prod’}{var_gtm_head}{/if} </head> <body> {if global:env == ‘prod’}{var_gtm_noscript}{/if} {par_barra_navigazione} <!– BANDA LOGO ***–> <div class=”banda_logo_worldbridge grid-x align-center text-center”> <div class=”small-8 medium-3 large-2 cell”> </div> </div> {exp:speedy:escape}{layout:contents}{/exp:speedy:escape} {embed=”_includes/_footer”} [removed][removed] [removed][removed] [removed][removed] [removed][removed] [removed][removed] {if segment_1 != ‘traduzioni’} <!– Landbot Chat home page –> [removed][removed] [removed] var myLandbot = new LandbotLivechat({ index: ‘https://landbot.io/u/H-241275-C4326OBIYADELOQQ/index.html’, }); [removed] [removed] // Show a proactive message after 3 seconds setTimeout(function() { myLandbot.sendProactive({ “message”: “Ciao, come posso aiutarti?”, “author”: “Brigitta”, “avatar”: “https://worldbridge.it/images/antea-50x50.png”, “extra”: { “hide_textbox”: true } }); }, 3000); [removed] {/if}

{if segment_1 == ‘traduzioni’} <!– Landbot Chat Traduzioni –> [removed][removed] [removed] var myLandbot = new LandbotLivechat({ index: ‘https://landbot.io/u/H-232908-AK2NDG6TU2E684TA/index.html’, accent: ‘#bc0000’, }); [removed] [removed] // Show a proactive message after 5 seconds setTimeout(function() { myLandbot.sendProactive({ “message”: “Ciao, ti servono info sulle traduzioni?”, “author”: “Brigitta”, “avatar”: “https://worldbridge.it/images/antea-50x50.png”, “extra”: { “hide_textbox”: true } }); }, 5000); [removed] {/if}
</body> </html> {/exp:speedy:fragment}

#15

Francesco Pensabene

THIS IS ONE “CHILD” TEMPLATE OF THE LAYOUT - If for example I strip off {exp:speedy:escape} from the {layout:set name=’title’}Corsi di lingua a Milano{/layout:set} I get this printed on the front-end: Corsi di lingua a Milano{/layout:set}


{layout=”_layout/_generico”}

{exp:speedy:fragment key=”corsi-milano”}

{exp:speedy:escape} {layout:set name=’title’}Corsi di lingua a Milano{/layout:set} {layout:set name=’meta_description’}Tutti i corsi di lingua a Milano di WorldBridge{/layout:set} {/exp:speedy:escape}

<!–*** LISTA CORSI –>
<div class=”grid-container”> <div class=”grid-x grid-padding-x align-center banda_titolo”> <div class=”cell small-8 medium-8 text-center”> <h1 class=”beh1 beMainColor”>Corsi di lingue a Milano</h1> </div> </div> <!–
LISTA CORSI ***–> <div class=”grid-x grid-margin-x banda”> {exp:channel:entries channel=”corsi” limit=”30” dynamic=”no” disable=”categories|member_data”} <div class=”cell small-12 medium-6 large-4 card_academy”> <a href=”http://{route=%27corsi-lingua/dettaglio-corsi-globale" title='{url_title}’ class=”link_container”> {par_immagine_corso} <h4 class=”title_academy beBold”>{title}</h4> {meta_description} <div class=”cta_academy”>Descrizione del corso <i class=”icona_freccia fas fa-arrow-right”></i></div> </div> {if no_results} <div class=”cell”> Non ci sono corsi in questa sezione </div> {/if} {/exp:channel:entries} </div> </div> {/exp:speedy:fragment}

#16

BoldMinded (Brian)

Can you strip those templates down to only the relevant code to recreate the problem… remove all extra html, channel:entries tags etc. thanks.

#17

BoldMinded (Brian)

All that extra template code is just noise, I need the simplest template code necessary to recreate the issue before I spend time looking into this.

#18

Francesco Pensabene

Layout:

{exp:speedy:fragment key="layout_generico"}
<!doctype html>
<html class="no-js" lang="it">
   <head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{exp:speedy:escape}{if layout:title}{layout:title}{if:else}WorldBridge{/if}{/exp:speedy:escape}</title>
  <meta name="description" content="{exp:speedy:escape}{layout:meta_description}{/exp:speedy:escape}">
   </head>
   <body>
   {exp:speedy:escape}{layout:contents}{/exp:speedy:escape}
   </body>
</html>
{/exp:speedy:fragment}

Template:

{layout="_layout/_test"}
{exp:speedy:fragment key="corsi-arabo-milano"}

 {exp:speedy:escape}
 {layout:set name='title'}this is a title{/layout:set}
 {layout:set name='meta_description'}this is a meta desc{/layout:set}
 {/exp:speedy:escape}
 
 <h1>This is the page content</h1>
{/exp:speedy:fragment}
#19

BoldMinded (Brian)

Francesco, you still haven’t answered the question: Are you still using full page static caching? Fragment caching and static caching are not meant to be used at the same time. They’re 2 completely different types of caching strategies.

#20

Francesco Pensabene

Hi Brian, sorry, no I’ve disabled it!

#21

BoldMinded (Brian)

You also don’t have the global=”yes” parameter as noted in the docs: https://docs.boldminded.com/speedy/docs/tags#template-layouts

#22

BoldMinded (Brian)

I just double checked, and this is what I have that works locally:

layout file:

{exp:speedy:fragment key="global-layout" global="yes"}
    {exp:speedy:escape}
        layout:title={layout:title}
    {/exp:speedy:escape}
    
    [before layout:contents]
    {exp:speedy:escape}{layout:contents}{/exp:speedy:escape}
    [after layout:contents]
{/exp:speedy:fragment}

template file:

{layout="layouts/main"}

{exp:speedy:fragment key="fragment-embed-test"}

 [before embed:cache/fragment-embed]
 {embed="cache/fragment-embed"}
 [after embed:cache/fragment-embed]
 
 {exp:speedy:escape}
  {layout:set name='title'}THIS IS THE TITLE{/layout:set}
 {/exp:speedy:escape}
 
{/exp:speedy:fragment}

This results in the layout:title={layout:title} line rendering correctly.

#23

Francesco Pensabene

Ok, to confirm in the template you have to escape the layout:set tags? Is that correct?

#24

BoldMinded (Brian)

Yep, as noted in the docs.

#25

Francesco Pensabene

Hi Bryan,

what is this line on your code up?

{embed=”cache/fragment-embed”}

#26

BoldMinded (Brian)

That embed is just me testing to make sure embeds work with caching and layout variables, which they do.

Login to reply