Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to add a number of redirects from old domains to new domains which I have done before using simple 301 redirects in my vhost files like:

<VirtualHost *:8080>
  ServerName olddomain.com
  ServerAlias www.olddomain.com
  Redirect 301 / http://www.newdomain.com/
</VirtualHost>

However this isn't working in my vhost file and I am assuming its because of the Varnish server running in front of Apache but not sure how to fix it. The main site, in the same vhost file, is using the same port, ex:

<VirtualHost *:8080>
  ServerName www.newdomain.com
  ...

</VirtualHost>

What am I missing? I've tried working with the varnish configuration file to add the redirects in there but ran into issues -- is that the best option?

share|improve this question
1  
Varnish obeys host headers in caching; it shouldn't cause any problems with this configuration. Can you provide the output of apachectl -S? And maybe also your VCL config? –  Shane Madden May 31 '13 at 5:03

1 Answer 1

I'm still not clear why the apache vhost above wasn't being recognized, perhaps due to something in the varnish vcl file that intercepted it but I was able to solve this eventually by adding a redirect there, following the instructions here https://www.varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

sub vcl_recv {
    if (req.http.host ~ "^(www\.)?oldexample\.com$") {
        error 750 "http://www.example.com/newlocation";
    } else if (req.http.host ~ "^(www\.)?ancientexample\.com$") {
        error 750 "http://newsite.com/ancient"
    }
 }

 sub vcl_error {
   if (obj.status == 750) {
       set obj.http.Location = obj.response;
       set obj.status = 302;  
       return(deliver);
   }
 }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.