1

I am trying to write a regular expression such as it has /admin in the middle and ends with .css or .js or other formats.

http://example.com/admin/static/style.css (SHOULD WORK)

http://example.com/admin/static/vendor.js (SHOULD WORK)

http://example.com/static/style.css (SHOULD NOT WORK)

I am trying to use this in nginx location block. I tried this

location /admin/\.(css|js)${

}

but not working.

Any ideas?

HBruijn
  • 72,524
  • 21
  • 127
  • 192

2 Answers2

0

Please try this for a case insensitive match (~*):

location ~* ^/admin/.+\.(css|js)$ {
    # more configuration
}

Add other file types separated by | like ^/admin/.+\.(css|js|png|gif|jpe?g)$.

Freddy
  • 1,999
  • 5
  • 12
0

What you may be missing is the section between "admin" and "css/js". This could work:

(.*)\/admin(.*)\.(css|js)

I also added the (.*) in the beginning, meaning that in front of /admin there may be additional characters.

Tobias
  • 1,236
  • 13
  • 25