1

i have setup the following nginx rewrite rule . But doesn't seems to be working,

*

location /images {
       rewrite ^(.*)$1 http://sub.domain.com/$1 permanent;
}

*

for images i'm trying to redirect to another domain. How could i make this work ?

0

You don't need regex capture here. Try this:

location /images {
    rewrite ^ http://sub.domain.com$request_uri permanent;
}
4
  • This one redirects, but after php prcessed the request. Php code redirects to get default.image if images not found and this default image being requested from sub.domain with the above rule. So the redirection should be somehow applied before php processing i guess... – cuteboyucsc Apr 8 '14 at 9:12
  • Please post the full configuration of your server. Please also give more details on what you actually want from the setup. Your comment implies that there is something else going on here. – Tero Kilkanen Apr 8 '14 at 12:31
  • i havent got anything special in nginx conf. As a fact when i request domain.com/image/my.img it redirects to sub.domain.com/image/my.img. But when i browse to the web page embeded with the image i get image not available(default image). I tried location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { rewrite ^(.*) sub.domain.com/$1 break; } Didnt work either – cuteboyucsc Apr 8 '14 at 15:04
  • Is the URL to the image correct in your web page? The break directive makes an internal redirect, and doesn't work at all the way you wrote it. If you want to make a browser redirect, you have to use permanent directive like in my example. – Tero Kilkanen Apr 8 '14 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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