3

I found some configuration of nginx contains:

if($args ^~ post=140) {
    rewrite ^ http://example.com/ permanent;
}

What does the ^ mean in rewrite ^ http://example.com/ permanent?

1
  • please specicy all the information that you want . i have some information of this but can't sure please chech on this link it will provide fully information od your question. nginx.org/en/CHANGES
    – Rahul Mandaliya
    Jul 6, 2011 at 13:35

1 Answer 1

5

It's a regexp metacharacter that matches the beginning of a string. Since all strings have a beginning, this regexp matches any string.

This is a typical nginx idiom for "redirect any URL to http://example.com/".

The $ metacharacter matching the end of a string would work as well, but ^ seems to be what everybody uses.

2
  • Just to confirm - the ^ is the first part of the rewrite, and what it matches, gets replaced with http://test.com/. So is this like doing ^.*, and matching everything? Why does a ^ by itself, work?
    – Cyclops
    Jul 6, 2011 at 14:26
  • 2
    @John: Regexps are not "anchored" by default. The regexp foo will match any URL with the word "foo" in it. The regexp ^foo will match any URL starting with the word "foo". And so the regexp ^ will match any string at all. .* would work just as well, but it would probably scan the whole string and thus take longer, I suspect.
    – Nemo
    Jul 6, 2011 at 15:36

Your Answer

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