Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx location regex not matching

Tags:

url

nginx

rewrite

Been trying this for several hours now but i am having a hard time figuring it out.

   location ~* ^\/sys\/assets\/(.*).css$   {
        try_files $uri $uri/ /sys/assets/stylesheets/$1;
   }

I am basically trying to make css files called from /sys/assets/file.css to fallback to /sys/assets/stylesheets/file.css

like image 966
John Dave Decano Avatar asked Sep 17 '14 19:09

John Dave Decano


1 Answers

Your first match group is file name without extension, while you're passing it to the last fallback URL where extension is expected.

Also there's no point of escaping forward slashes. They have no special meaning here.

server {

    listen 80;
    server_name localhost;

    root  /var/www/localhost/www;

    location ~* ^/sys/assets/(.+)\.css$ {
      try_files $uri /sys/assets/stylesheets/$1.css;
    }

}
like image 68
saaj Avatar answered Nov 15 '22 05:11

saaj