SOLVED: How do I serve cache from a different file path?


#1

Hi,

I’m trying to create a configuration with the following logic:

visible to the web                origin server path

feeds.example.com          =>  origin-www.example.com/feed/default
feeds.example.com/news     =>  origin-www.example.com/feed/news
feeds.example.com/latest   =>  origin-www.example.com/feed/latest
feeds.example.com/maths    =>  origin-www.example.com/feed/tag/maths
feeds.example.com/science  =>  origin-www.example.com/feed/tag/science

Then anything else should redirect to the root “/” which maps to /feed/default on the origin.

Is this possible with Fastly?


#2

Definitely. You can do this with a little VCL, our configuration language:

if (req.url == "/") {
  set req.url = "/feed/default";
} else if (req.url == "/news") {
  set req.url = "/feed/news";
}
... etc ...

If you had thousands of these, or you wanted to adjust them dynamically via API calls, I’d recommend looking at using an Edge dictionary.


#3

Thanks for the advice, I’ve added a custom VCL like this:

sub vcl_recv {
#FASTLY recv

  if (req.url == "/") {
    set req.url = "/feed/default";
  } else if (req.url == "/news") {
    set req.url = "/feed/news";
  } else {
    set req.url = "/feed/default";
  }
}

I added the final else block to catch any other URLs that might hit the address.