# NGINX Location Matching Question - Case insensitive matching at the start of a URI

**URL:** <https://www.ruby-forum.com/t/nginx-location-matching-question-case-insensitive-matching-at-the-start-of-a-uri/237920>\
**Category:** NGINX\
**Created:** [December 6, 2013, 12:30am UTC](https://www.ruby-forum.com/t/nginx-location-matching-question-case-insensitive-matching-at-the-start-of-a-uri/237920 "2013-12-06T00:30:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [December 6, 2013, 12:30am UTC](https://www.ruby-forum.com/t/nginx-location-matching-question-case-insensitive-matching-at-the-start-of-a-uri/237920/1 "2013-12-06T00:30:19Z")

</div>

Hi,

I’m running in a somewhat urgent issue where I have to make a  
case-insensitive location match on a URI segment that is at the  
beginning of the URI.

so I want to match

/uri-segment/\*  
/URI-segment/\*  
/Uri-Segment/\*  
etc…

I know that this will match the start of the URI:  
location ^~ /uri-segment

and this will match regardless of case:  
location ~\* /uri-segment(.\*)

But chaining them together and using ^~\*doesn’t seem to work. Is this  
possible? If so what am I missing?

Thanks

---

<div class="post-metadata">

**Author:** ![brads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brads](https://www.ruby-forum.com/u/brads)\
**Post date:** [December 6, 2013, 12:40am UTC](https://www.ruby-forum.com/t/nginx-location-matching-question-case-insensitive-matching-at-the-start-of-a-uri/237920/2 "2013-12-06T00:40:50Z")

</div>

On 5 December 2013 23:29, Brad Van S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> /URI-segment/\*  
> /Uri-Segment/\*  
> etc…
> 
> I know that this will match the start of the URI:  
> location ^~ /uri-segment

It will, but that’s not what the regex-alike “^” means there. There,  
it means “… and if this /does/ match, stop immediately and don’t  
consider any regex matches”. See  
[http://wiki.nginx.org/HttpCoreModule#location](http://wiki.nginx.org/HttpCoreModule#location) for more information. (I  
personally consider this a really bad choice of character by nginx -  
it /always/ confuses me!)

> and this will match regardless of case:  
> location ~\* /uri-segment(.\*)
> 
> But chaining them together and using ^~\*doesn’t seem to work. Is this  
> possible? If so what am I missing?

Seeing how you said this is urgent, I’ll not do what I /normally/ do  
and just give you pointers to the docs that’ll help you 🙂

You want

location ~\* ^/uri-segment(.\*) { }

HTH,  
Jonathan

---

<div class="post-metadata">

**Author:** ![brads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brads](https://www.ruby-forum.com/u/brads)\
**Post date:** [December 6, 2013, 12:51am UTC](https://www.ruby-forum.com/t/nginx-location-matching-question-case-insensitive-matching-at-the-start-of-a-uri/237920/3 "2013-12-06T00:51:21Z")

</div>

Thanks for the quick response!

Looks like that is matching how I intend… however it (of course)  
revealed another issue in my app layer 🙂 But at least the NGINX configs  
seems correct now.

Thanks!
