Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How to trig this rule only when I have parameters in url, otherwise I will match on an alias.

location ~^/static/photos/.* {
    rewrite ^/static/photos/(.*)$  /DynamicPhotoQualitySwitch/photos/$1  break;
    expires     7d;
    proxy_pass http://foofoofoo.com;
    include /etc/nginx/proxy.conf;
     }
share|improve this question
    
For URL-routing/rewriting questions, it really helps to provide concrete examples of URLs along with descriptions of how you want them handled. –  Rob Starling Jul 4 '13 at 21:16
    
... especially if you're willing to give away half of your rep for a good answer. –  Rob Starling Jul 4 '13 at 21:16

3 Answers 3

Replace the * (meaning 0 or more) to a + (meaning 1 or more)

For example, this:

location ~^/static/photos/.* {
    rewrite ^/static/photos/(.*)$  /DynamicPhotoQualitySwitch/photos/$1  break;
    expires     7d;
    proxy_pass http://foofoofoo.com;
    include /etc/nginx/proxy.conf;
}

becomes:

location ~^/static/photos/.+ {
    rewrite ^/static/photos/(.+)$  /DynamicPhotoQualitySwitch/photos/$1  break;
    expires     7d;
    proxy_pass http://foofoofoo.com;
    include /etc/nginx/proxy.conf;
}
share|improve this answer
    
arguments(query string) are not present in "location", so it will not work, my question are not about regex. but thank you –  Christophe Debove Jun 29 '13 at 7:38
    
You're right. Sorry about that. –  Daniel Paul Searles Jun 29 '13 at 7:42

Here is my answer now that I understand the question better:

Have you tried try_files?

For example it would probably look something like:

try_files /DynamicPhotoQualitySwitch/photos/$args /path/for/no/args;

location /path/for/no/args {
    expires     7d;
    proxy_pass http://foofoofoo.com;
    include /etc/nginx/proxy.conf;
}
share|improve this answer

You could add a condition to check if the $args parameter is not empty:

location ~^/static/photos/.* {
  if ($args != ''){
    rewrite ^/static/photos/(.*)$  /DynamicPhotoQualitySwitch/photos/$1  break;
    expires     7d;
    proxy_pass http://foofoofoo.com;
    include /etc/nginx/proxy.conf;
  }  
}
share|improve this answer
    
sounds good I will test it asap –  Christophe Debove Jun 29 '13 at 7:39
    
location can not be included in if condition –  Christophe Debove Jun 29 '13 at 13:12
    
This is untested too, but try moving the if condition inside of location, as I edited above. –  alanthing Jun 30 '13 at 16:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.