When working on a copy of a live WordPress website it can be handy not to have to duplicate the uploaded files in wp-content/uploads, whilst still allowing the creation of new uploads during testing and development without affecting the production website.
The configuration below can be added inside a server{} block inside an NGINX configuration file to redirect any requests for files in wp-content/uploads that don’t exist back to the live server, www.example.com.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
server { # ... other server configuration... # Match anything in wp-content/uploads and if it doesn't exist, use the rule for @prod_serv location ~ "^(.*)/wp-content/uploads/(.*)$" { try_files $uri @prod_server; } # Send a temporary http redirect to the browser, redirecting the request to # For a permanent redirect change the status code below from 302 to 301 location @prod_serv { return 302 $scheme://www.example.com$request_uri; } # ... rest of the server config below ... } |
This solution was based on the information at http://wordpress.stackexchange.com/a/215189 and https://www.nginx.com/blog/creating-nginx-rewrite-rules/ .
You must log in to post a comment.