When a non-existing image is asked to the server hosting Wordpress, it returns a standard 404 page which result in:

  • PHP having to render a page which cannot be cached and loads ALL the plugins
  • 152 server requests
  • 1.2 MB transferred
  • a load time of 3 seconds

I found out that I can avoid this mess with a .htaccess rule at the beginning of the file, but sometimes this breaks some Cache Plugin and however it doesn't help with the broken url.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(css|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ - [nocase,redirect=404,last]

Howw can I implement something similar inside the PHP? Is there any hook / filter to achieve a similar task?

  • I know the question is broad and not perfect, but there is a huge problem. I will appreciate any suggestion on how to improve it (also in english) – Revious Nov 8 '19 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.