Caveat: I don’t know that specific plugin, but if the url after /uploads is exactly the same, then:
– You could create a relatively simple rewrite in .htaccess to catch these. This is very simple, creates very small load on your server, since the redirect will be served even before WordPress would have started loading. But the visitor will still have one extra round-trip to your server before the content may be requested from the server.
– You could add a filter to the hook when a post is saved to the database. Neatest solution: makes sure that you immediately serve the correct URL, without any additional filtering. But acts only upon saving. You’d need to either re-save all posts and pages, or do a search&replace on your database for all previous entries. (Or catch older entries through the .htaccess rewrite above)
If needed, I can try and find the rewrite command for you, but you should be able to find what you need, there are several resources on this, some better than others. Just make sure that the rewrite is marked as L (last).
Thanks.
Can i get an example of the .htaccess file and can htaccess also add a referrer to my redirect? cloudfront is set to allow requests from my domain.
Thanks
Referrer is a value in a http-request that the visiting browser may or may not include.
Try to include the following in your .htaccess file. The sooner, the better, but it must be before the WordPress part:
RewriteEngine on
RedirectMatch 301 ^/wp-content/uploads(.*) https://foobarfoobar.cloudfront.net/wp-content/uploads$1
The .htaccess file is construed by the webserver Apache. This rewrite command will send a 301 redirect (moved permanently) to the address in the last part of the command for any request that matches the first part of the request, copying the part in parenthesis into the position of $1
Thanks for this..
Once it solves my issue i would mark this as resolved.
Sure. Take your time.
Still, I’d suggest that you consider finding a way to directly include the correct cdn address in your posts. This will allow visitors to have their pages load a little bit quicker, since they won’t need to first contact your server for every included image.
Worked but denied permission by amazon firewall which validates with referrer value.
if there is any way you know of kindly direct me. i have search every where but cannot come up with one.
I was actually thinking there is a function or CONSTANT that defines uploads url in wordpress or if there is a way i can do a php search and replace on the function that returns post content.. any ideas??