Reputation: 861
I am using NGINX for a project, and I have WordPress installed. I would like to hide the wp-content directory and want to rewrite the image URLs for images.
I want to support multiple extensions (jpg,jpeg,gif,png).
Another thing that I needed is a dynamic folder, it contains the ID of a user.
I used the following code but without luck, The number 1
should also become dynamic but for now I want to start with a simply rewrite, to keep things simple.
location /images/auctions/1/(.*).(png|jpg|gif) {
rewrite /wp-content/plugins/myplugin/uploads/auctions/1/(.*).(png|jpg|gif) /images/auctions/1/$1.$2;
}
I searched for NGINX rewrite and some other search queries but nothing that really answers my needs.
Upvotes: 2
Views: 10035
Reputation: 861
Ok I think I got some kind of way that works for me (only not yet with the dynamic folder /1/
but I probably will fix that later).
Here is the code for the nginx config:
location ~ ^/images/(.*)$ {
try_files $uri $uri/ /wp-content/plugins/myplugin/uploads/$1;
}
Edit:
Below the code that also handles the dynamic ID folder of the user:
location ~ ^/images/(.*)/(.*)$ {
try_files $uri $uri/ /wp-content/plugins/veilgarant/uploads/$1/$2;
}
Upvotes: 4