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 ?

2 Answers 2

3

I finally did it like this :

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

It gives a 302 code and just works

1

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

2
  • I tried that but it didn't work Commented Apr 13, 2011 at 10:40
  • You're sure you included the =, and you reloaded your config? I just tested it and it worked fine for me. Commented Apr 13, 2011 at 12:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.