Patrioticcow
Patrioticcow

Reputation: 27038

How to match everything after slash to use as an nginx rewrite?

I have these test cases:

/test
/test/
/test/whatever

I would like to write an nginx rewrite rule that only targets /test/whatever

I currently have

rewrite ^/(test/)(.*) /some-other-page; but this targets all the above cases.

Any ideas?

Upvotes: 2

Views: 2815

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

The ^/(test/)(.*) will match /test/ because .* can match an empty string.

You may use

^/test/(.+)

The .+ will require at least 1 char after /test/.

Upvotes: 2

Related Questions