Query links result in infinite redirects

XMLWordPrintable

Details

• Type: Story
• Status: Done
• Resolution: Done
• Fix Version/s: None
• Component/s:
• Labels:
None
• Story Points:
2.1
• Team:
SQuaRE
• Urgent?:
No

Description

It is really nice that the search fills in the URL so it can be copied and shared, but using the URL results in a redirect loop. This can be triggered by either:
1 doing a search and hitting the reload button in the browser

Activity

Hide
Jonathan Sick added a comment -

I think we've cracked this. One change that needed to be be made was in the search app to always include a trailing slash in the path (i.e. /search/?query=vault). Gatsby natively prefers trailing slashes. Before we were rewriting the browser URL with just the directory name (i.e. /search?query=vault), but that actually triggers a 301 redirect on the client.

Second, we've modified the Fastly Varnish configuration for directory redirects to access the index.html file in the S3 bucket if the path ends with a trailing slash.

Before, the redirect VCL was:

 if( req.url ~ "/$" ) {  set req.url = req.url "index.html"; }  The new redirect VCL is:  if ( req.url.path ~ "/$" ) {  set req.url = req.url.path "index.html" }

So the key parts of this are:

• Test if the path ends with "/" rather than the whole URL. This lets us be compatible with query strings.
• When setting the new req.url, append "index.html" to the path, which excludes the query string.

Show
Jonathan Sick added a comment - I think we've cracked this. One change that needed to be be made was in the search app to always include a trailing slash in the path (i.e. /search/?query=vault) . Gatsby natively prefers trailing slashes. Before we were rewriting the browser URL with just the directory name (i.e. /search?query=vault ), but that actually triggers a 301 redirect on the client. Second, we've modified the Fastly Varnish configuration for directory redirects to access the index.html file in the S3 bucket if the path ends with a trailing slash. Before, the redirect VCL was: if ( req.url ~ "/$" ) { set req.url = req.url "index.html" ; } The new redirect VCL is: if ( req.url.path ~ "/$" ) { set req.url = req.url.path "index.html" } So the key parts of this are: Test if the path ends with "/" rather than the whole URL. This lets us be compatible with query strings. When setting the new req.url, append "index.html" to the path, which excludes the query string.

People

Assignee:
Jonathan Sick
Reporter:
Simon Krughoff
Watchers:
Jonathan Sick, Simon Krughoff