NginX - how to redirect 404 to different locations, based on the URI filetype

32 Views Asked by At

Currently I have this in my nginx config:

error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /error.html;
    location = /error.html {
        root /usr/share/nginx/html;
                ssi on;
        internal;
        auth_basic off;
    }

This does its job perfectly by displaying the error.html page whenever there is any of the above error. This works with all files/URLs.

What I want is to redirect the .HTML 404 error pages to the index, while leaving the above code to do the job for the rest.

For example, if visitors accesses /some-inexistent-page.html (or .htm, .asp etc), they should get redirected to the site's index page rather than loading the default error.html above.

Is it possible to have both? How?

0

There are 0 best solutions below