1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Xenforo attachments/rewrites

Discussion in 'XenForo Questions and Support' started by D.O.A., Oct 31, 2014.

  1. D.O.A.

    D.O.A. Well-Known Member

    Hi, just a question for anyone out there who may know... with xenforo "pretty url's" and how the attachments are presented, does xenforo append .html to attachments during the normal course?
    I know with pretty rewrites off it runs through /index.php?attachments, not sure what happens when 'on', or what handles it internally.

    eg; at a log level (not in the URL)
    I ask only as I am working on some pcre rewriting for nginx and I'm not entirely sure if it's me on the nginx end or xenforo appending that index.html. Needless to say, image URL's return a 404, so it's probably my crappy rewrite?
     
    Last edited: Oct 31, 2014
  2. Chris D

    Chris D XenForo Developer Staff Member

    D.O.A. likes this.
  3. D.O.A.

    D.O.A. Well-Known Member

    Thanks for the reply, narrows it down for me... If a mod reads this perhaps it can be moved to server/troubleshooting.

    I'm trying to prevent attachment hotlinking in nginx, not .jpg files the ID extensions actual attachments use. The regex seems correct, I can get things to work with pretty url's off, but not when on. (config for testing only - location security not added)

    Redirect will always work but with pretty url's the image attachment itself will 404.

    Code:
     server {
        listen   80;
        ...
    
        location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        }
    
        location ~ \.php$ {
        ....
        }
    
        location ~* ([0-9a-zA-Z])+-(png|jpg|jpeg|gif)[.]([0-9]+)/$ {
        valid_referers server_names blocked *.mydomain.com;
        if ($invalid_referer) {
        rewrite ^(.*)$ url/to/goatse.gif break; #oh shi..
        }
      }
    }
    Capture.PNG

    domain.com/attachments/someimage-jpg.3/

    404's with the error;

    Code:
    [error] 12819#0: *7508 ".../attachments/someimage-jpg.3/index.html" is not found (2: No such file or directory), client: xxx.xxx.x.xx, server: domain.com, request: "GET /attachments/someimage-jpg.3/ HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/sdaasd-asdada-asdadsasd-asdad.2/"
    
    But the hotlink image with still redirect regardless, if linked elsewhere. Debug log is not helping.

    edit;

    Oddly enough
    Code:
    root ..;
    index index.html index.php;
    error_log ..;
    
    Remove index.html and it becomes
    Code:
    .../attachments/someimage-jpg.3/index.php" is not found
    :unsure:
     
    Last edited: Oct 31, 2014
  4. Mike

    Mike XenForo Developer Staff Member

    From what I understand, Nginx only matches one location block per request "attempt" (try_files retries the attempt with the new URL). So basically, the try_files block isn't being hit after your referrer block... block. I don't know what the best practice is here unfortunately.
     

Share This Page