G
G
gregorypetrov2017-05-25 11:19:46
Nginx
gregorypetrov, 2017-05-25 11:19:46

Custom error page for non-existent files: how to do it?

Colleagues, good day to all! I ran into this question:
in the folder with the wordpress theme there is a script for handling requests to non-existent pages - 404.php . On the site I'm working with, there is just a redirect to the main one:

<script>
location.href='http://example.com'; 
</script>

But this only works if we request a non-existent page, like example.com/nonexistent
But how to make it show not the standard nginx '404 Not Found' message, but some special page when requesting a non-existent file ? Those. when requesting example.com/wrongimage.jpg, example.com/wrongdocument.pdf Please tell me in which direction to dig, because I'm not even sure that the problem is solved completely inside WordPress. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tallmange, 2017-05-25
@p00h

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        . . .
        error_page 404 /404.php;
        location = /404.php {
                root /usr/share/nginx/html;
                internal;
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question