1. Set up Fastly VCL snippets in Magento
Log in as an admin user on your Magento store and navigate to Store → Configuration → Advanced → System → Full Page Cache. Confirm that the Caching Application is set to Fastly CDN, then enter your Fastly Service ID and API token.
Open the Custom VCL Snippets section. You need to add two snippets: one to define the Similar AI backend, and one to route requests to it.
Backend definition (type: init, priority: 100)
This snippet defines a new Fastly backend that points to your Similar AI proxy host. Replace <<client_com>> with your domain name (e.g. example if your site is example.com).
backend F_similarai_proxy {
.host = "<<client_com>>.page.similar.ai";
.port = "80";
.probe = {
.dummy = false;
.request = "HEAD / HTTP/1.1" "Host: storage.googleapis.com" "Connection: close";
.expected_response = 200;
.interval = 60s;
.timeout = 2s;
.window = 5;
.initial = 4;
.threshold = 4;
}
}Request routing (type: recv, priority: 100)
This snippet checks the URL path and routes matching requests to the Similar AI backend. The /s/ prefix is the subfolder agreed upon during onboarding. F_Host_1 is your origin host in Fastly.
if (req.url.path ~ "/s/") {
set req.http.Host = "<<client_com>>.page.similar.ai";
set req.backend = F_similarai_proxy;
} else {
set req.backend = F_Host_1;
}After adding both snippets, go to the Automatic Upload & Service Activation section and click Upload VCL to Fastly to push the configuration live.
2. Fix backend ordering in Fastly admin
Fastly inserts any defined backends after VCL snippets in the generated configuration. This means the snippets added from Magento admin will not route correctly on their own. The fix is to attach an always-false condition to the default backend so Fastly does not override your routing logic.
Step A: Create a false condition
Log in to the Fastly Admin dashboard. Go to Conditions in the left nav, click Create Condition, and add a condition that always evaluates to false:
req.url == "1"
Step B: Attach the condition to your origin
Go to Origins/Hosts in the left nav, select your origin host, and attach the always-false condition you created above. This prevents Fastly from inserting a default backend assignment that would override your VCL snippet routing.
Final generated VCL
After applying both the snippets and the condition workaround, the generated VCL will look like this. Notice the false condition at the bottom prevents the default backend from taking effect:
# Snippet magentomodule_proxypage : 100
if (req.url.path ~ "/s/") {
set req.http.Host = "client_com.page.similar.ai";
set req.backend = F_similarai_proxy;
} else {
set req.backend = F_Host_1;
}
# default conditions
if (!req.http.Fastly-SSL) {
error 801 "Force SSL";
}
# Request Condition: host Prio: 10
if( req.url == "1" ) {
set req.backend = F_Host_1;
}The req.url == "1" condition never matches a real request, so the default backend assignment is effectively disabled.
Ready to add new pages to your Magento store?
Similar AI creates SEO-optimized pages and serves them through your existing domain using a simple reverse proxy setup. Get started with a demo.