Friday, October 24, 2014

Modifying a rewrite rule in nginx for Subdomain

I did a little rewrite rule a little while ago to redirect ppl who directly access my site's image to image pages instead,



for example a person accessing www.mysite.com/i/asdf.jpg to www.mysite.com/pic/asdf



this is the rewrite rule i used :




location /i/image_(\d+).(gif|jpg|jpeg|png)$ {
root /home/mysite/public_html;
valid_referers www.mysite.com mysite.com;
if ($invalid_referer) {
rewrite ^ http://www.mysite.com/pic/$1 permanent;
}
}


I made a subdomain of the directory 'i' which contains all the images. so its like thsi now http://i.mysite.com/




Is it possible to make a rewrite like the one above so if the file is directly accessed by a different referer via subdomain it will hit the same rewrite rule ?



I tried this in the subdomain server{...} :



location /image_(\d+).(gif|jpg|jpeg|png)$ {
root /home/mysite/public_html/i;
valid_referers www.mysite.com mysite.com;
if ($invalid_referer) {
rewrite ^ http://www.mysite.com/pic/$1 permanent;

}
}


but no luck so far :(
thx :)

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...