Using regex in nginx location block for variables Using regex in nginx location block for variables codeigniter codeigniter

Using regex in nginx location block for variables


Two possible problems:

  1. You don't have any brackets in your regex so it's not going to be a capturing group. And you missed out the ~* command to tell Nginx to do a regex match.

    location ~* ^/backups/(\w+)$ {    try_files $uri $uri/ /backups/$1/index.php;}
  2. The last parameter in a try_files is magic. It doesn't actually try to see if the file exists. Instead it rewrites the request URI with the last parameter and reprocesses the request, which is moderately surprising. To fix this you can (and should) fall back to either a 404 or other page.

    location ~* ^/backups/(\w+)$ {    try_files $uri $uri/ /backups/$1/index.php /404_static.html; }location = /404_static.html {    root   /documents/projects/intahwebz/intahwebz/data/html/;    internal;}

btw if you have further issues you should enable rewrite_log on; which will write the matching to the servers error file at notice level, and helps figure out location matching issues.