0

I am trying to redirect any location that gives 404 to the front page and change the response code to 302.

According to nginx documentation this should be possible?

https://nginx.org/en/docs/http/ngx_http_core_module.html#error_page

But I keep getting 404 with the old 404 page. Caches are cleaned, cloudflare is in development mode and purged.

What am I doing wrong?

server {
   ...
   error_page 404 =302 https://example.com/home/;
   ...
2
  • Nginx config seems OK to me. Have you tried visiting Nginx directly, bypassing anything in between (Cloudflare etc.)? Try curl maybe
    – iBug
    Oct 29 at 20:36
  • Also, if the location is processed by proxy_pass/fastcgi_pass, then you have to use proxy_intercept_errors/fastcgi_intercept_errors directive.
    – Alexey Ten
    Oct 29 at 21:39

1 Answer 1

0

Two things to try :

(1) Change
error_page 404 =302 https://example.com/home/;
to
error_page 404 =302 /home/;
[ I might suggest that you should also test without changing the response code ]

(2) Put that in a location Context ( not within the Server Context ) & then test with that location level.
It will ensure that your Current location Context is over-riding that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .