rosell-dk / webp-express

Wordpress plugin for serving autogenerated WebP images instead of jpeg/png to browsers that supports WebP
GNU General Public License v3.0
221 stars 63 forks source link

Nginx for static request & Apache for dynamic request #575

Open sallsabil opened 1 year ago

sallsabil commented 1 year ago

Hello My hosting uses Nginx for static request & Apache for dynamic request. The redirection to webp images doesn't work. I like to use redirection instead of alter HTML. Any solution ?

Also the support of hosting told me I should pass them a code to set in server for webp image conerters. Do you have any ?

Testing redirection to existing webp uploads Copying files for testing Copying JPEG to uploads folder (webp-express-test-images/fs35cN.JPEG). ok We now have a jpeg stored here: /home/myusn/domains/mywebsite.com/public_html/wp-content/uploads/webp-express-test-images/fs35cN.JPEG

Copying dummy webp to the cache root for uploads. ok We now have a webp file stored here: /home/myusn/domains/mywebsite.com/public_html/wp-content/webp-express/webp-images/uploads/webp-express-test-images/fs35cN.JPEG.webp

Lets check that browsers supporting webp gets the WEBP when the JPEG is requested Making a HTTP request for the test image (pretending to be a client that supports webp, by setting the "Accept" header to "image/webp") Request URL: https://www.mywebsite.com/wp-content/uploads/webp-express-test-images/fs35cN.JPEG Response: 200 OK Response headers:

  • server: ArvanCloud
  • date: Tue, 04 Oct 2022 20:12:10 GMT
  • content-type: image/jpeg
  • content-length: 3195
  • last-modified: Tue, 04 Oct 2022 20:12:08 GMT
  • etag: "633c9398-c7b"
  • expires: Tue, 18 Oct 2022 20:12:10 GMT
  • cache-control: max-age=1209600
  • x-xss-protection: 1; mode=block
  • ar-sid: 2074
  • ar-atime: 0.676
  • ar-cache: BYPASS
  • ar-request-id: bef14ff8fec91ea04bac2b526e1c26df
  • accept-ranges: bytes

Bummer. As the "content-type" header reveals, we got the jpeg. Additionally, the content-length reveals that we did not get the webp (we know that the file we put is exactly 6964 bytes). So we can conclude that the rewrite did not happen The test FAILED. Diagnosing rewrites Running a special designed capability test to test if rewriting works with .htaccess files Result: Yes, rewriting works. It seems something is wrong with the .htaccess rules then. You could try to change "Destination structure" - the rules there are quite different. It could also be that the server has cached the configuration a while. Some servers does that. In that case, simply give it a few minutes and try again. Note that if you cannot get redirection to work, you can switch to "CDN friendly" mode and rely on the "Alter HTML" functionality to point to the webp images. If you do a bulk conversion and make sure that "Convert upon upload" is activated, you should be all set. Alter HTML even handles inline css (unless you select "picture tag" syntax). It does however not handle images in external css or which is added dynamically with javascript

themes Copying files for testing Copying JPEG to themes folder (webp-express-test-images/QZOvps.JPEG). ok We now have a jpeg stored here: /home/myuser/domains/mywebsite.com/public_html/wp-content/themes/webp-express-test-images/QZOvps.JPEG

Copying dummy webp to the cache root for themes. ok We now have a webp file stored here: /home/myuser/domains/mywebsite.com/public_html/wp-content/webp-express/webp-images/themes/webp-express-test-images/QZOvps.JPEG.webp

Lets check that browsers supporting webp gets the WEBP when the JPEG is requested Making a HTTP request for the test image (pretending to be a client that supports webp, by setting the "Accept" header to "image/webp") Request URL: https://www.mywebsite.com/wp-content/themes/webp-express-test-images/QZOvps.JPEG Response: 200 OK Response headers:

  • server: ArvanCloud
  • date: Tue, 04 Oct 2022 20:12:34 GMT
  • content-type: image/jpeg
  • content-length: 3195
  • last-modified: Tue, 04 Oct 2022 20:12:34 GMT
  • etag: "633c93b2-c7b"
  • expires: Tue, 18 Oct 2022 20:12:34 GMT
  • cache-control: max-age=1209600
  • x-xss-protection: 1; mode=block
  • ar-sid: 2025
  • ar-atime: 0.030
  • ar-cache: BYPASS
  • ar-request-id: d9a051ebbec6b32768117fed8ff5962b
  • accept-ranges: bytes

Bummer. As the "content-type" header reveals, we got the jpeg. Additionally, the content-length reveals that we did not get the webp (we know that the file we put is exactly 6964 bytes). So we can conclude that the rewrite did not happen The test FAILED. Diagnosing rewrites Running a special designed capability test to test if rewriting works with .htaccess files Result: Yes, rewriting works. It seems something is wrong with the .htaccess rules then. You could try to change "Destination structure" - the rules there are quite different. It could also be that the server has cached the configuration a while. Some servers does that. In that case, simply give it a few minutes and try again. Note that if you cannot get redirection to work, you can switch to "CDN friendly" mode and rely on the "Alter HTML" functionality to point to the webp images. If you do a bulk conversion and make sure that "Convert upon upload" is activated, you should be all set. Alter HTML even handles inline css (unless you select "picture tag" syntax). It does however not handle images in external css or which is added dynamically with javascript