Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I found some configuration of nginx contains:

if($args ^~ post=140) {
    rewrite ^ permanent;

What does the ^ mean in rewrite ^ permanent?

share|improve this question

migrated from 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. – Rahul Mandaliya Jul 6 '11 at 13:35

1 Answer 1

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".

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 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.