Take the 2-minute tour ×
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 ^ http://test.com/ permanent;
}

What does the ^ mean in rewrite ^ http://test.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
add comment

1 Answer

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://test.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
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 '11 at 15:36
add comment

Your Answer

 
discard

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