SiteTree::get_by_link() problem

silverstripe-3
Tags: #<Tag:0x00007f10c7498520>

#1

Silverstripe Version: 3.21

Question:

I’m trying to put a Silverstripe website behind a varnish server. I have a controller that given a url path returns its content in json format. I use SiteTree::get_by_link(“page path”) to fetch the page content. For some reason this function returns false when accessed thru the varnish server.

Can someone tell me why this happends?

Thanks


#2

I think you might need to do a bit of debugging with what’s being passed to that method. If you have a look at the code, silverstripe-cms/SiteTree.php at d33e36c032ba1daafcfeec1d0e7b1b6e352a4e8f · silverstripe/silverstripe-cms · GitHub you can see that it’s just looking in the database for a matching URL segment.
How is the URL segment being passed? Could your Varnish proxy be stripping something out of the request? It might be helpful if you can share some relevant code snippets.


#3

Hi Dorset,

The segment is passed via query string. Here is an example:

Via Varnish:
http://obvarnish.eastus.cloudapp.azure.com/api/resource?segment=/es/para-ti/cuentas-bancarias/cuentas-de-cheques/&locale=es-US

Via backend (working):
http://obwww-staging.azurewebsites.net/api/resource?segment=/es/para-ti/cuentas-bancarias/cuentas-de-cheques/&locale=es-US

Har File:

Screenshots:

Code:

I have enabled nested urls.

SiteTree::enable_nested_urls();

Line of code I use to get page info.

I hope this help. Thanks for responding!


#4

When I test from here, I get very similar responses to both.

I do notice that your Varnish config is stripping out all the session data, including the locale, etc. but I’m guessing that’s being covered in the URL anyway.