Patrioticcow
Patrioticcow

Reputation: 27048

How to redirect all 404 pages to the same URL in nginx?

I have setup a 404 page in nginx error_page 404 /404.php;

So that if I go to website.com/some-bad-url I see the content form 404.php

My question is how to have website.com/some-bad-url redirect to 404.php directly form nginx and have the browser show the 404.phppage directly ?

Any ideas?

Upvotes: 1

Views: 3587

Answers (1)

Richard Smith
Richard Smith

Reputation: 49702

The error_page directive will normally perform an internal redirect. If you specify a scheme and a server name, it will perform an external redirect, but obviously can only use 3xx response codes.

For example:

error_page 404 $scheme://$host/404.php;

See this document for details.

Upvotes: 3

Related Questions