'Nginx rewrite rule with/without caret

Having an nginx location prefix section where the rewrite rule regex starts with the location itself, is there a difference between having the regex with or without the caret (^)? Doesn't seem so, since it will return the first match, but maybe a counterexample exists?

For example, location with ^:

location /smth/ {
    rewrite ^/smth(.*)$ /somewhere/else$1 break;
}

And without:

location /smth/ {
    rewrite /smth(.*)$ /somewhere/else$1 break;
}

Seem functionally equivalent.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source