开发者

Need help rewriting an Nginx rule for subdomain

开发者 https://www.devze.com 2023-02-05 08:00 出处:网络
I did a little rewrite rule a little while ago to redirect ppl who directly access my site\'s image to image pages instead,

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.example.com mysite.com;
  if ($invalid_referer) {
   rewrite ^ http://www.example.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 it will hit the same rewrite rule ?

thx :)

UPDATE : now using this :

   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;
    }
}
}

Htaccess rewrites :

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&a开发者_Go百科mp;pop=1 [QSA,L]


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)$ /view.php?name=image_$1.$2 last;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消