How Does vcl_error Work?



  • Udaya Uday

    Hi Squee,

    We have a requirement  to redirect any requests only from or to

    I have tried various methods (vcl & error) in the fastly fiddle and did not work as per the requirement.

    Here is the magento2 website where we use Fastly CDN.


    Comment actions Permalink
  • Squee

    Hi Udaya,

    Thanks for reaching out. 

    We're happy to look at this with you, but I suspect we'll need more details to provide you with a solution. 

    As for the fiddle, the host on the fiddle is some variation on `exec<number>`. If you want to write VCL to be able to test redirects coming in from another host, try setting that host at the top of `vcl_recv`. That would look something like:

    set = "";

    You would only want to do this in the fiddle to create the testing environment you need. Please don't put this line in your code unless you intend to rewrite the host for your origin to find.

    If you have further questions, please don't hesitate to open a ticket with support by emailing

    Comment actions Permalink
  • Anish Asokan

    Hi Squee


    Thank you so much Squee, This was a real life-saver for me.

    And this worked perfectly fine on my magento-cloud where we have fastly.


    We recently migrated a magento1 website from their old server to magento2 in magento-cloud.


    So, I was in a situation where I needed a custom URL redirect for:


    `<anything>` should be redirected to `<anything>`


    I basically made use of your rule:


    in `vcl_recv`

    # 301 Redirects
    if ( == "" && req.url ~ "^/us/(.*)") {
    error 607 "Custom RegEx 301 Redirect";


    in `vcl_error`


    # 301 Redirects
    if (obj.status == 607) {
    set obj.status = 301;
    set obj.response = "Moved Permanently";
    set obj.http.Location = "" req.url;
    synthetic {""};
    return (deliver);


    This helped me with redirecting all old `/us/` store URL's to be redirected to new US store domain ``


    This documentation was really helpful.


    Comment actions Permalink

Please sign in to leave a comment.