0

I'm using cdn subdomain. The files are now available at cdn.website.com/uploads/*.(img|png|zip|..).

The old URL structure is cdn.website.com/*.(img|png|zip|..).

This code works fine;

 location ~* ^/.+\.(png|jpg|doc|gif|html|jpeg|zip|rar)$ {
     rewrite ^/(.*) http://cdn.website.com/uploads/$1 permanent;
 }

Routing from the main directory to the "uploads" directory is working properly. But when I open a file on the uploads array, it replicates the "uploads" directory. Example;

cdn.website.com/uploads/x1.jpg

cdn.website.com/uploads/uploads/x1.jpg

cdn.website.com/uploads/uploads//uploads/x1.jpg

...

Many redirect problem.

How to fix this problem? Thank you for helping.

0

The location pattern needs to be narrowed down.

location ~* ^/[a-zA-Z0-9_-]+\.(png|jpg|doc|gif|html|jpeg|zip|rar)$ {
     rewrite ^/(.*) http://cdn.website.com/uploads/$1 permanent;
}

Match requests that start with / and contain any of the following characters a-z, A-Z, 0-9, _ or - and end with .png, .jpg, .doc, .gif, .html, .jpeg, .zip and .rar. This excludes requests within a sub directory.

Also, haven't tested the regex pattern but that should work.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.