1

I want nginx to handle 404 error status and redirect them to another domain.

In headers "Location:" is updated but status is still 404 but should be 301.

Here is my code :

# error handling
error_page 404 @404;
log_not_found off;
proxy_intercept_errors on;

and :

location @404 {
  rewrite ^ http://www.example.com/404.html? permanent;
}

So following command lynx -head -dump 'http://localhost:9999/a_404_error' gives me :

HTTP/1.1 404 Not Found
Server: nginx/0.8.54
Date: Mon, 11 Apr 2011 18:59:12 GMT
Content-Type: text/html
Content-Length: 169
Connection: close
Location: http://www.example.com/404.html

Any idea ?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
jney
  • 233
  • 1
  • 2
  • 8

2 Answers2

3

I finally did it like this :

error_page 404 http://www.example.com/404.html

It gives a 302 code and just works

jney
  • 233
  • 1
  • 2
  • 8
1

error_page 404 = @404 will allow location @404 to set the response status

kolbyjack
  • 7,854
  • 2
  • 34
  • 29