Fastly causing trailing slash issues - HTACCESS shows 'PERMANENTLY MOVED' when rewrite added whilst Fastly Enabled


#1

Hi,

My website is using Fastly CDN to improve site speed. We have 2 versions of the website being indexed - pages with and pages without a trailing forward slash. This is normally resolved by adding a rewrite in the HTACESS file – but for some reason with FASTLY enabled this rewrite displays ‘permanently moved’ across the whole website and makes it unusable.

We have pinpointed this is due to the CDN because when we bypass the CDN using the local hosts file – the issue disappears. I have been provided documentation to make amendments on the ‘edge’ to resolve this from within Fastly – but neither myself or any of my developers have any familiarity with Varnish/VCL. Regardless of this, I have committed myself to trying to learn Varnish and implement the changes Fastly have recommended.

BREAKDOWN OF TASKS ATTEMPTED:

  1. I have followed the ‘Generating HTTP redirects at the edge’ guide as best to my ability. I assigned the following settings:
    Name: Trailing Slash
    Status: 301 Moved Permanently
    MIME TYPE: empty
    Response: empty

For the new request condition -
Name: Trailing Slash
Apply if… req.url ~ “^/”

I also tried -

Name: Trailing Slash
Status: 301 Moved Permanently
MIME TYPE: empty
Response: empty

For the new request condition -
Name: Trailing Slash
Apply if… req.url ~ “/$”

  1. I proceeded down the guide and attempted the ‘Create a new header and condition’ with the assumption this would need to be done also.
    Name: Trailing Slash
    Type/Action: Response / Set
    Destination: http.Location
    Source: req.url “”
    Ignore If Set: No
    Priority: 10

I also tried a couple of other things:

  1. Adding a ‘VCL snippets’
    Type: none
    Source: if (req.url ~ “/$”)
    set req.url = req.url “”;

  2. Adding ‘Custom VCL’
    boilerplate as provided
    and if (req.url ~ “/$”) {
    set req.url = req.url “”;

Has anyone had any experience with removing trailing slashes from url’s being handled by Fastly?

Thanks in advance.
Kind Regards,
Keiran