How to get the correct HTTP status?

Asked

Viewed 468 times

6

I tried to get the error "status" like this:

error_page 403 /error.php;
error_page 404 /error.php;

But $_SERVER['REDIRECT_STATUS'] return 200, already in Apache he return 404 (the expected result).

How to define variables $_SERVER[REDIRECT_STATUS], $_SERVER[REDIRECT_REQUEST_METHOD] and $_SERVER[REDIRECT_URL] using the Nginix?

  • I’m sorry, I deleted the answer because she was from another question.

  • http://php.net/manual/en/function.http-response-code.php

  • @Curious Leandrocurious But how do I detect the redirect?

  • Correct "retouch".

  • @Guill in SE communities you can edit posts from other users when you encounter grammatical errors.

  • I found very little to edit. Some users don’t agree with someone editing their posts for minor errors. But it’s a matter of interpretation. Finally, corrections applied and that’s what matters.

  • So @Guill any issue that favors the SE communities are welcome and if one day you edit some in good faith and the original author still doesn’t like it, I recommend you show this link: http://meta.pt.stackoverflow.com/a/3749/3635 A good afternoon xará (I believe his name is William Too)

Show 2 more comments

1 answer

2


After a brief search, I found this ikiwiki, there are some improvements that can be made, but the idea is that the location fake solves the problem, in time I will improve the code or add a new example.

Basic example:

# Configura um local "falso" para
error_page 404 @fakeroute404;

# Acessa o local falso
location @fakeroute404 {
    ...# Outros dados

    include /etc/nginx/fastcgi_params; #inclui os parametros fastcgi

    fastcgi_param REQUEST_METHOD "GET"; # Configura o metodo
    fastcgi_param REDIRECT_STATUS 404;  # Configura o estado
    fastcgi_param REDIRECT_URL $uri;    # Configura a URL
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.