How to get `$_POST` query when 404 redirected through .htaccess?

前端 未结 3 638
别跟我提以往
别跟我提以往 2021-01-18 08:29

This question is somewhat related to my previous question. The trick of using $_SERVER[\'REDIRECT_QUERY_STRING\'] seems to work only for $_GET var

3条回答
  •  遥遥无期
    2021-01-18 08:59

    With the following directive:

    ErrorDocument 404 /index.php
    

    the apache webserver does an internal redirect to the new location. Internal means, the client (browser) won't change the URL in it's address bar because that redirect is not communicated to the browser.

    Because it's an redirect, the POST request is turned into a GET request.

    You can see this by looking into the following two $_SERVER variables:

    $_SERVER['REDIRECT_REQUEST_METHOD'] # POST
    $_SERVER['REQUEST_METHOD'] # GET
    

    So in short, you can not use the ErrorDocument directive to do URL rewriting for HTTP POST requests.

    You need to use the mod_rewrite module for this or create your own apache handler.

提交回复
热议问题