PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] How to match nginx location with keyWord in the middle of URI

 September 01, 2022     nginx, nginx-config, nginx-location, nginx-reverse-proxy     No comments   

Issue

Can location directive resolve the incoming requests not at the beginning, but anywhere in the middle of the URI.

for example i have to match location based on environment.

location /uat/ {.....}

location /sit/ {.....}

The request coming in would be /abc/customer/uat/ide

How to make a match when the environment name is not in the beginning of the URI.

Thanks in advance.


Solution

You can have something like this

server {
  listen ...;
  server_name _;

  location ~* .*/sit/.*$ {
    ...
  }

  location ~* .*/uat/.* {
    ...
  }
}

Breakdown of regex ~* .*/uat/.*:

  1. ~* -> Makes the matching case insensitive
  2. .* -> Any character any number of times
  3. /uat/ -> Match /uat/
  4. .* -> Any character any number of times


Answered By - NetanMangal
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing