Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Jul 6 '11 at 15:45

This question came from our site for professional and enthusiast programmers.

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 '11 at 13:35
up vote 5 down vote accepted

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.

share|improve this answer
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 '11 at 14:26
@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 '11 at 15:36

Your Answer


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