G
G
Gleb Starkov2011-07-28 06:34:45
htaccess
Gleb Starkov, 2011-07-28 06:34:45

How to preserve query parameters when redirecting via ErrorDocument in .htaccess?

Found that the parameters of get and post requests are lost
if the direction is via ErrorDocument.
For example, the content of .htaccess is:
ErrorDocument 404 /test.php
Content of test.php

echo '$_REQUEST:<br />';
  var_dump($_REQUEST);
  echo '<br />';

  echo '$_POST:<br />';
  var_dump($_POST);
  echo '<br />';

  echo '$_GET:<br />';
  var_dump($_GET);
  echo '<br />';

  echo '<br />--------------------<br />';

  echo 'POST-TEST:<br />';
  echo '<form action="" method="post">
        <input type="text" name="bla" /><br />
        <input type="submit" value="Send" />
      </form>';

Example edelen.ru/bla
At the same time, if you go directly to edelen.ru/test.php,
everything works.
If the direction is through mod rewrite, then, of course, the parameters are not lost, but still I can’t understand why
they are lost through ErrorDocument.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
G
Gleb Starkov, 2011-07-28
@colonel

In general, the answer is apparently - no way:
Here they write:

The bottom line is to use the Error Document directive to redirect all non-existent requests to one script.
The main significant disadvantage of Error Document is the impossibility of intercepting POST data!
To receive POST data form a form action to a real URL.
Also, the disadvantages include the fact that the error.log of the server is clogged, which prevents the identification of real errors that need to be fixed.

Thanks everyone for the replies.

M
mark_ablov, 2011-07-28
@mark_ablov

action="test.php"?

G
Gleb Starkov, 2011-07-28
@colonel

In this case, the request will go directly to test.php, which is logical,
and redirection to ErrorDocument will not occur.
The question is how to save the parameters of the request passing through the ErrorDocument

K
Kindman, 2011-07-28
@Kindman

In the .htaccess file we write:

ErrorDocument 404 /404.php
and, here you can play with this file:
404.php
<?php
echo "<xmp>";
print_r($GLOBALS);
For all requests, it prints a dump of PHP environment variables. How to handle variable values ​​is a matter of taste. Among these variables will be your parameters (except perhaps the body of the POST request).
By the way, the body of the POST request can also be found somewhere.

R
Riateche, 2011-07-28
@Riateche

You specify a url in the ErrorDocument, so a redirect occurs. Try to specify a script file, then if an error occurs, control will be transferred to this script without a redirect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question