title: Need help rewriting an Nginx rule for subdomain
body: <p>I did a little rewrite rule a little while ago to redirect ppl who directly access my site's image to image pages instead,</p>
  
  <p>for example a person accessing www.mysite.com/i/asdf.jpg to www.mysite.com/pic/asdf</p>
  
  <p>this is the rewrite rule i used :</p>
  
  <pre><code>location /i/image_(\d+).(gif|jpg|jpeg|png)$ {
    root /home/mysite/public_html;
    valid_referers www.example.com mysite.com;
    if ($invalid_referer) {
     rewrite ^ http://www.example.com/pic/$1 permanent;
    }
   }
  </code></pre>
  
  <p>I made a subdomain of the directory 'i' which contains all the images. so its like thsi now <a href="http://i.mysite.com/" rel="nofollow">http://i.mysite.com/</a></p>
  
  <p>Is it possible to make a rewrite like the one above so if the file is directly accessed by a different referer it will hit the same rewrite rule ?</p>
  
  <p>thx :)</p>
  
  <p>UPDATE : 
  now using this : </p>
  
  <pre><code>   server {
   access_log off;
  
    error_log  logs/vhost-error_log warn;
    listen    80;
    server_name i.imgzzz.com;
      root /home/imgzzz/public_html;
    #location ~ ^/pic/ { alias /home/imgzzz/public_html/i; }
          location ~ ^/pic/(.*)$ { alias /home/imgzzz/public_html/i/$1; }
  valid_referers i.imgzzz.com www.imgzzz.com imgzzz.com;
  location ~ /image_(\d+).(gif|jpg|jpeg|png)$ {
      if ($invalid_referer) {
          rewrite /image_(\d+).(gif|jpg|jpeg|png)$ /pic/image_$1 last;
      }
  }
  }
  </code></pre>
  
  <p>Htaccess rewrites : </p>
  
  <pre><code>RewriteBase /
  Options +FollowSymlinks
  #RewriteEngine on
  rewritecond %{http_host} ^imgzzz.com [nc]
  rewriterule ^(.*)$ http://www.imgzzz.com/$1 [r=301,nc] 
  
  RewriteCond %{HTTP_REFERER} !^http://(www\.)?imgzzz.com/.*$ [NC]
  RewriteRule i/image_(\d+)\.(jpg|jpeg|gif) pic/$1 [L]
  
  RewriteRule ^pic/([0-9]+)/{0,1}$ view.php?name=$1 [QSA,L]
  RewriteRule ^pic/full/([0-9]+)/{0,1}$ view-f.php?name=$1 [QSA,L]
  RewriteRule ^pic/([0-9]+)/feature/$ view.php?name=$1&amp;pop=1 [QSA,L]
  </code></pre>