2013-07-02 61 views

回答

1

可以有2例。你要告訴客戶端的瀏覽器,圖像已被移動

A.客戶端重定向[1],使用時:

sub vcl_recv { 
    # ... 
    if (req.url ~ "(?i)\.png$") { 
    error 750 "http://" + req.host + regsub(req.url, "(?i)\.png$", ".jpg$"); 
    } 
    # ... 
} 

sub vcl_error { 
    # ... 
    if (obj.status == 750) { 
    set obj.http.Location = obj.response; 
    set obj.status = 302; 
    return(deliver); 
    } 
    # ... 
} 

B.服務器端改寫[2],如果用這個你要改變內部的要求,而不告訴客戶:

sub vcl_recv { 
    # ... 
    if (req.url ~ "(?i)\.png$") { 
    set req.url = regsub(req.url, "(?i)\.png$", ".jpg$"); 
    } 
    # ... 
} 

PD:請不要複製您的問題

[1] https://www.varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

[2] https://www.varnish-cache.org/trac/wiki/RedirectsAndRewrites