You can use two major methods to instruct Varnish to redirect a URL: use a module, or edit the
.htaccess file. Acquia Cloud caches 301 redirects in Varnish for a minimum of 15 minutes by default. If you need to change the length of time the 301 is cached, you can use one of the following methods:
Redirect module (Drupal 7)
The Redirect module creates the max-age header that is sent to Varnish for redirects. The header is also created later when you enable Allow redirects to be saved into the page cache in the module's settings.
The Redirect module cache settings also apply to other redirects. You can override these on a global or per redirect basis.
Redirects using .htaccess
To set Varnish-cachable 301 redirects from
.htacess, you must set an environment variable using
mod_rewrite and conditionally add caching headers with mod_headers. Because Acquia Cloud already sets a 15 minute cache, this variable is only needed if you want to cache in Varnish for more than 15 minutes.
As an example, this is an
.htaccess rule to create a 301 redirect from
http://example.com/bar/* that Varnish will cache for two weeks:
RewriteRule ^foo/(.*)$ http://example.com/bar/$1 [R=301,L,E=longcache:1] Header always set Cache-Control "max-age=1209600" env=longcache