In Magento, you can set your secure and non-secure URLs explicitly. This works as expected in most cases, but can cause some issues when you have to specify full URLs or need to make any AJAX requests. When using the Nexcess Turpentine extension to enable Magento and Varnish to work together and you wish to only support traffic at and not, you would need to enable the setting in the Turpentine module to normalize the host.

However, when you have the normalize host setting configured and you visit your Magento site at, assuming you have Apache set to use a 301 redirect to, this will not work, and your visitor will be stuck at until they click on any of the links on the site. Fortunately, there is a relatively simple enhancement that needs to be made to the vcl file that handles the redirection entirely within Varnish. ##Varnish 301 Redirect Solution The solution is to add or modify the vcl_recv and vcl_error functions in your vcl file with what is shown below. Once you restart Varnish, anyone visiting will quickly be redirected to, making everything work as expected.

sub vcl_recv {
    if ( == "") {
        set = "";
        error 750 "http://" + + req.url;

sub vcl_error {
    if (obj.status == 750) {
        set obj.http.Location = obj.response;
        set obj.status = 301;