[wp-hackers] cheap 404 serving

Otto otto at ottodestruct.com
Tue Oct 16 15:12:53 UTC 2012

On Tue, Oct 16, 2012 at 8:27 AM, "Matthias P. Würfl" <mpw at taquiri.de> wrote:
> I meant conditions that show that this file should be served by Wordpress.
> These URIs ending "/" or ".html" should be served by Wordpress. Others
> (".jpg") should not be served by Wordpress even if the file doesn't exist.

Many sites do, and you cannot predict that in advance. WordPress is
perfectly capable of serving content outside of text/html, and many
plugins make it do so for special cases.

> Headers don't *do*, they just *tell* what the client expects. If the
> Accept-header is "image/jpeg" i know theres no sense in sending this request
> to WP (correct me if I'm wrong).

Consider yourself corrected. I've made a plugin that does exactly this
for special circumstances
(http://wordpress.org/extend/plugins/dynamic-image-resizer/) and I've
seen plugins that do other forms of dynamic image handling and serving
from within WordPress as well.

Obviously, serving an image dynamically is not the preferred solution
for speed in all cases, but sometimes speed is not the end-all and
be-all of website management.

> I don't understand that. How can that catch all the requests to
> /favicon.ico, /robots.txt, /phpmyadmin and /othernonexistant.file? Where's
> php in here at all?

Why would it be in there?

Here's my nginx rules:

if (!-e $request_filename) {
  rewrite ^/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
  rewrite ^.*$ /index.php last;

That's the working set for a multisite setup. Note that in my case,
404's *are* being served by WordPress, as well as many other things,
including some images, some XML files, RSS feeds, and a load of other
stuff that doesn't fall into text/html.

> A request to a static file takes 20ms, a request to Wordpress takes 400ms
> (if not cached). So far so good, but: a request to a non-existing "foo.gif"
> that is requested by the html produced by wordpress takes 400ms as well.

If you're getting a lot of 404 errors, then I'd suggest solving the
underlying problem instead. Why are there so many invalid requests to
your site? You mention "a gallery site where all images disappear for
some reasons"... To me, that suggests "broken site" and whether the
thing crashes or not after that is irrelevant, those images should not
have disappeared, for any reason.


More information about the wp-hackers mailing list