MikeW
MikeW

Reputation: 4809

How to rewrite query params and redirect site in varnish

I'm looking to use varnish to rewrite the query param for this site and redirect the domain also

http://www.example.com/?s=SearchTerm ==> http://www.example2.com/search?q=SearchTerm

So far I've tried to get the first part ie. query params to rewrite using regsub ie.

sub vcl_recv {
  if (req.http.host == "example.com") {
    set req.http.url = regsub(
    req.url,
        "^/?s=.*",
        "^/?search=.*"
    );
    set req.backend = www01;
    return (pass);
    }
 }

however the original url doesn't change in the varnishlog - anyone see the issue?

Cheers

Upvotes: 1

Views: 1041

Answers (1)

Pr Shadoko
Pr Shadoko

Reputation: 1698

I had same issue with obsolete code got from the web. You need to replace

set req.backend = www01;

by

set req.backend_hint = www01;

Upvotes: 1

Related Questions