404通过.htaccess重定向时,如何获取$ _POST查询? [英] How to get `$_POST` query when 404 redirected through .htaccess?
问题描述
这个问题与我的有关上一个问题。使用 $ _ SERVER ['REDIRECT_QUERY_STRING']
的技巧似乎仅对 $ _ GET
变量有效。
This question is somewhat related to my previous question. The trick of using $_SERVER['REDIRECT_QUERY_STRING']
seems to work only for $_GET
variables.
好吧,我有一个 index.php
文件,该文件处理所有 404重定向。
Well, I've an index.php
file which handles all the 404 redirects
.
如果用户请求的页面不存在,例如 apple.php?item = 23
,然后使用 $ _ SERVER ['REDIRECT_QUERY_STRING']
我可以获得 $ _ GET
变量 item = 23
,但是如果变量不是 $ _ GET
而是 $ _ POST
,则 $ _ SERVER ['REDIRECT_QUERY_STRING']
不起作用。
If a user requests for a page which doesnt exist, say, apple.php?item=23
, then using $_SERVER['REDIRECT_QUERY_STRING']
I can get the $_GET
variable item=23
, but if the variable is not $_GET
but $_POST
then $_SERVER['REDIRECT_QUERY_STRING']
doesn't work.
如何获取 $ _POST
变量,当我使用以下.htaccess设置将其重定向到 index.php
时
How can I get $_POST
variable when I redirect it to index.php
using the following .htaccess setting
ErrorDocument 404 /index.php
ErrorDocument 404 /index.php
推荐答案
检查答案此处: http://www.brainonf ire.net/blog/apache-pitfall-errordocument-post/
我用这个解决了问题。
或将其放入您的.htaccess文件中:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /yourErrorDocument.php [L]
这篇关于404通过.htaccess重定向时,如何获取$ _POST查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!