XF 1.4 Can somebody help me rewrite URL attachment

I have a problem with Xenforo's attachment link, and really need your help !
Can you tell me how to redirect /attachments/657.xyz/ to /attachments/657/ only with xyz is a variable file extension.

I am now using Nginx web service.

Thank you very much