1

I have a rewrite that nginx calls like so:

        location ~* (css)$ {
rewrite ^(.*),(.*)$ /min/index.php?f=$1,/min/$2 last;
        }

And it's used on pages like this:

http://domain.com/min/framework.css,dropdown.css

Works all fine and dandy, but it's not scalable. Adding another element to the URL means I have to directly edit the nginx config. Ideally, I'd like to have nginx rewrite according to how many comma-delimited parameters are passed through the URL, rather than setting a fixed amount in the config. Is this possible?

1 Answer 1

1

As far as I understand there is no solution using pure regular expressions. But you can make use of Perl capabilities, e.g.

http {
  perl_set $css_uri_arg 'sub {
    my $r = shift;
    my ($first,@rest) = split(/,/, $r->uri);
    join(',', ($first, map { "/min/$_"; } @rest));
  }';

  server {
    location ~* (css)$ {
      rewrite ^ /min/index.php?f=$css_uri_arg last;
    }
  }
}

Perl module is not built into Nginx by default, you should turn it on at build time. The documentation is here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.