Mecanik / cloudflare-image-resizing-worker

Cloudflare Image Resizing worker for WordPress
Apache License 2.0
41 stars 9 forks source link

onerror=redirect relative URL #16

Open rjdusk opened 1 year ago

rjdusk commented 1 year ago

Hi @Mecanik, firstly thank you so much for this worker code, I've been using it to great success on a WordPress website I manage.

However I've noticed a few line in my server error logs that look like this:

2023/11/01 00:16:43 [error] 48664#48664: *449359 open() "/www/xucobuce_886/public/resources/guides/mobile-self-checkout-benefits/onerror=redirect/wp-content/uploads/2021/03/Yuka-scanning-app-cheerios.png" failed (2: No such file or directory), client: 52.167.144.136, server: www.scandit.com, request: "GET /resources/guides/mobile-self-checkout-benefits/onerror=redirect/wp-content/uploads/2021/03/Yuka-scanning-app-cheerios.png HTTP/2.0", host: "www.scandit.com:64972"

Any idea what maybe causing these errors? It looks like the onerror redirect is a relative URL instead of an absolute URL. Probably some config I may have missed, but I can't see where. Thanks!

Mecanik commented 1 month ago

Hi,

Thanks for reporting this and I apologize for the late reply. I will investigate and get back with an update.

chr4ss12 commented 1 week ago

same issue here, all my urls look like this. I think it does not work when you host your blog as https://www.mydomain.com/subdirectory/wp-content

Mecanik commented 1 week ago

same issue here, all my urls look like this. I think it does not work when you host your blog as https://www.mydomain.com/subdirectory/wp-content

It should work if you set the site URL. Try to edit config.php manually and set the URL there.

chr4ss12 commented 1 week ago

here is my setup explained:

I have domain lets call it example.com, this domain purely runs NextJS and all of it is behind CloudFlare, that's my main website and contains a lot of stuff regarding just website, nothing to do with wordpress,

I've also now set up a custom wordpress(hosting it call it wordpress.com), and I am using CloudFlare 'proxy/mirroring' to essentially 'host it / mirror it' at

https://example.com/blog

This is done through CloudFlare worker that rewrites urls on the fly. So far so good. I experiemnted with a lot of wordpress plugins and they all seemed really weird and complicated, until I saw this, which is more or less how I do my main website images anyways, through CloudFlare cdn-cgi.

So for reference, if I want to resize images I need to pass them through https://example.com/cdn-cgi (note without /blog).

I have now tried this plugin, and what it seems to do is to write all of the images/other urls to this format (paraphrased more or less as I don't have direct access to links right now, but the idea is right):

srcset=https://example.com/blog/cdn-cgi/format=auto,onerror=reject/wp-content/uploads/image.jpg

this is not correct, but this is:

srcset=https://example.com/cdn-cgi/format=auto,onerror=reject/blog/wp-content/uploads/image.jpg

For now, I changed/hardcoded everything myself to make it work, however I have no generic solution to share.

Mecanik commented 5 days ago

here is my setup explained:

I have domain lets call it example.com, this domain purely runs NextJS and all of it is behind CloudFlare, that's my main website and contains a lot of stuff regarding just website, nothing to do with wordpress,

I've also now set up a custom wordpress(hosting it call it wordpress.com), and I am using CloudFlare 'proxy/mirroring' to essentially 'host it / mirror it' at

https://example.com/blog

This is done through CloudFlare worker that rewrites urls on the fly. So far so good. I experiemnted with a lot of wordpress plugins and they all seemed really weird and complicated, until I saw this, which is more or less how I do my main website images anyways, through CloudFlare cdn-cgi.

So for reference, if I want to resize images I need to pass them through https://example.com/cdn-cgi (note without /blog).

I have now tried this plugin, and what it seems to do is to write all of the images/other urls to this format (paraphrased more or less as I don't have direct access to links right now, but the idea is right):

srcset=https://example.com/blog/cdn-cgi/format=auto,onerror=reject/wp-content/uploads/image.jpg

this is not correct, but this is:

srcset=https://example.com/cdn-cgi/format=auto,onerror=reject/blog/wp-content/uploads/image.jpg

For now, I changed/hardcoded everything myself to make it work, however I have no generic solution to share.

Your situation is unique, however when using the worker you have full control over the code and you can manually change it to reflect your needs. It grabs by default /blog because that's where your images are coming from, this is not a bug; it works as expected. Your only option in this situation remains manual adjusting to grab the images from your desired location.