Re: Request for a no capture rewrite directive enhancement
I think Igor is suggesting PERL named captures. Although, it appears to me the correct syntax would rather be (?name...), as perlre docs http://perldoc.perl.org/perlre.html#Extended-Patternsstate. Then, just use you first syntax (omitting the 'set' directives). --- *B. R.* On Wed, May 28, 2014 at 12:02 PM, Igor Sysoev i...@sysoev.ru wrote: On 28 May 2014, at 08:55, Peter Mescalchin peter.mescalc...@gmail.com wrote: Thanks Igor, I had explored that method already, sadly (as you know) alias is given as an absolute path meaning I can't use this block of config within multiple virtual hosts which I include; - would have to re-write this same block of config for each Virtual host modifying the alias path prefix. And since alias man page explicitly states that $document_root can't be used it's not possible to complete this config in a reusable way. (e.g. alias $document_root/path/to/$1/$2; would be perfect). Alas, I think what I have (storing the captures in temp vars) is the only real solution thus far. Unless the penny hasn't dropped in my head? :) Then you can set these variable directly in regex: location ~ ^/[a-f0-9]{16}/(?resource_typecss|js)/(?resource_path.+)” { -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
On 28 May 2014, at 19:39, B.R. reallfqq-ng...@yahoo.fr wrote: I think Igor is suggesting PERL named captures. Although, it appears to me the correct syntax would rather be (?name...), as perlre docs state. Then, just use you first syntax (omitting the 'set' directives). You a re right, I have mistaken. -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
Fantastic Igor - I didn't know that you could do named captures in Nginx - good to know. That solves it rather nicely. And thanks B.R. - yep, that syntax is part of PCRE. Pete I think Igor is suggesting PERL named captures. Although, it appears to me the correct syntax would rather be (?name...), as perlre docs http://perldoc.perl.org/perlre.html#Extended-Patterns state. Then, just use you first syntax (omitting the 'set' directives). --- *B. R.* On Wed, May 28, 2014 at 12:02 PM, Igor Sysoev igor at sysoev.ru wrote: On 28 May 2014, at 08:55, Peter Mescalchin peter.mescalchin at gmail.com wrote: Thanks Igor, I had explored that method already, sadly (as you know) alias is given as an absolute path meaning I can't use this block of config within multiple virtual hosts which I include; - would have to re-write this same block of config for each Virtual host modifying the alias path prefix. And since alias man page explicitly states that $document_root can't be used it's not possible to complete this config in a reusable way. (e.g. alias $document_root/path/to/$1/$2; would be perfect). Alas, I think what I have (storing the captures in temp vars) is the only real solution thus far. Unless the penny hasn't dropped in my head? :) Then you can set these variable directly in regex: location ~ ^/[a-f0-9]{16}/(?resource_typecss|js)/(?resource_path.+)” { -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
Yup the location directive uses the PCRE library to interpret regex. Its docs doesn't mention that the regex are PCRE, but the hint is given away on the build from sources http://nginx.org/en/docs/configure.htmlpage. It reminds me that not so long ago I mixed up named captures and subpatterns syntax trying to play with PCRE in location... but that is another story ;o) Glad I could help! --- *B. R.* On Thu, May 29, 2014 at 4:09 AM, Peter Mescalchin peter.mescalc...@gmail.com wrote: Fantastic Igor - I didn't know that you could do named captures in Nginx - good to know. That solves it rather nicely. And thanks B.R. - yep, that syntax is part of PCRE. Pete I think Igor is suggesting PERL named captures. Although, it appears to me the correct syntax would rather be (?name...), as perlre docs http://perldoc.perl.org/perlre.html#Extended-Patterns state. Then, just use you first syntax (omitting the 'set' directives). --- *B. R.* On Wed, May 28, 2014 at 12:02 PM, Igor Sysoev igor at sysoev.ru wrote: On 28 May 2014, at 08:55, Peter Mescalchin peter.mescalchin at gmail.com wrote: Thanks Igor, I had explored that method already, sadly (as you know) alias is given as an absolute path meaning I can't use this block of config within multiple virtual hosts which I include; - would have to re-write this same block of config for each Virtual host modifying the alias path prefix. And since alias man page explicitly states that $document_root can't be used it's not possible to complete this config in a reusable way. (e.g. alias $document_root/path/to/$1/$2; would be perfect). Alas, I think what I have (storing the captures in temp vars) is the only real solution thus far. Unless the penny hasn't dropped in my head? :) Then you can set these variable directly in regex: location ~ ^/[a-f0-9]{16}/(?resource_typecss|js)/(?resource_path.+)” { -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Request for a no capture rewrite directive enhancement
Hello Nginx developers, speaking to Maxim Konovalov over Twitter, suggested this would be the better place to get an answer to my suggestion. Basically what I would like to see is the ability to use a rewrite directive without the need to capture the current URI, which in turn overwrites $1,$2,$x captures made within a location directive. Best to explain via an example: https://gist.github.com/magnetikonline/11364574 As you can see, this works (and works well) but the need to use set to save copies of $1/$2 seems a little wasteful. Digging through the documentation I can't seem to find a way of using rewrite without blowing away/not capturing the current URI. Thoughts? Pete ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
What about: location ~ ^/[a-f0-9]{16}/(css|js)/(.+) { expires 30d; return $scheme://$host/$1/$2? break; } ? You could add the 301 code for permanent redirect, see http://nginx.org/r/return --- *B. R.* On Wed, May 28, 2014 at 1:52 AM, Peter Mescalchin peter.mescalc...@gmail.com wrote: Hello Nginx developers, speaking to Maxim Konovalov over Twitter, suggested this would be the better place to get an answer to my suggestion. Basically what I would like to see is the ability to use a rewrite directive without the need to capture the current URI, which in turn overwrites $1,$2,$x captures made within a location directive. Best to explain via an example: https://gist.github.com/magnetikonline/11364574 As you can see, this works (and works well) but the need to use set to save copies of $1/$2 seems a little wasteful. Digging through the documentation I can't seem to find a way of using rewrite without blowing away/not capturing the current URI. Thoughts? Pete ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
Thanks for the reply BR. That's not quite what I'm after - rewrite does an internal redirect, return will tell the browser to redirect. This recipe is all about CSS/JS cache busting of requested assets. Make sense? What about: location ~ ^/[a-f0-9]{16}/(css|js)/(.+) { expires 30d; return $scheme://$host/$1/$2? break; } ? You could add the 301 code for permanent redirect, see http://nginx.org/r/return --- *B. R.* ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
On 28 May 2014, at 03:52, Peter Mescalchin peter.mescalc...@gmail.com wrote: Hello Nginx developers, speaking to Maxim Konovalov over Twitter, suggested this would be the better place to get an answer to my suggestion. Basically what I would like to see is the ability to use a rewrite directive without the need to capture the current URI, which in turn overwrites $1,$2,$x captures made within a location directive. Best to explain via an example: https://gist.github.com/magnetikonline/11364574 As you can see, this works (and works well) but the need to use set to save copies of $1/$2 seems a little wasteful. Digging through the documentation I can't seem to find a way of using rewrite without blowing away/not capturing the current URI. location ~ ^/[a-f0-9]{16}/(css|js)/(.+) { expires 30d; alias /path/to/$1/$2; } -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: Request for a no capture rewrite directive enhancement
Thanks Igor, I had explored that method already, sadly (as you know) alias is given as an absolute path meaning I can't use this block of config within multiple virtual hosts which I include; - would have to re-write this same block of config for each Virtual host modifying the alias path prefix. And since alias man page explicitly states that $document_root can't be used it's not possible to complete this config in a reusable way. (e.g. alias $document_root/path/to/$1/$2; would be perfect). Alas, I think what I have (storing the captures in temp vars) is the only real solution thus far. Unless the penny hasn't dropped in my head? :) Pete location ~ ^/[a-f0-9]{16}/(css|js)/(.+) { expires 30d; alias /path/to/$1/$2; } -- Igor Sysoev http://nginx.com ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx