dongquqiao2010 2015-11-15 22:33
浏览 75
已采纳

.htaccess不允许带有ErrorDocument 404的$ _POST变量

I'm building a CMS over an MVC framework I'm also building, but I'm stuck here. The full code can be found at this link to github.

Ok, the problem I'm having is with this .htaccess file:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]
 RewriteCond %{REQUEST_METHOD} !POST [NC]
</IfModule>

<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

When I run the code on "auth/login" via this ajax request:

$.ajax({
  type: "POST",
  url: "auth/login",
  dataType: "json",
  data: { username: username, password: password, token: token_value }
})

When I run:

$username = $_POST['username'];
$password = $_POST['password'];
$token = $_POST['token'];
$postdata = array('username' => $username, 'password' => $password, 'token' => $token);
print_r($post_data);
print_r($_SERVER);

I get:

Array (
    [username] => 
    [password] => 
    [token] => 
)
Array(
[REDIRECT_REQUEST_METHOD] => POST
[REDIRECT_STATUS] => 404
[HTTP_HOST] => [omitted]
[HTTP_CONNECTION] => keep-alive
[CONTENT_LENGTH] => 71
[HTTP_ACCEPT] => application/json, text/javascript, */*; q=0.01
[HTTP_ORIGIN] => [omitted]
[HTTP_X_REQUESTED_WITH] => XMLHttpRequest
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
[CONTENT_TYPE] => application/x-www-form-urlencoded; charset=UTF-8
[HTTP_REFERER] => [omitted]/auth
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,fr;q=0.6
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] => <address>Apache/2.4.7 (Ubuntu) Server at [omitted] Port 80</address>

[SERVER_SOFTWARE] => Apache/2.4.7 (Ubuntu)
[SERVER_NAME] => [omitted]
[SERVER_ADDR] => [omitted]
[SERVER_PORT] => 80
[REMOTE_ADDR] => [omitted]
[DOCUMENT_ROOT] => [omitted]
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] => 
[CONTEXT_DOCUMENT_ROOT] => [omitted]
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => [omitted]/public_html/index.php
[REMOTE_PORT] => 60135
[REDIRECT_URL] => /auth/login
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /auth/login
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1447625662.493
[REQUEST_TIME] => 1447625662
)

I know the above block of code works because I've tried it on a static "test.php" file and it outputs the username/password/method information submitted by this ajax request.

I really feel like the problem lies within my .htaccess file because when I force a 200 OK header it still considers it a 404 or something? I'm not sure but its scrubbing the $_POST. This issue isn't related to my php.ini or apache2.conf, since I've tested that out already and I'm able to receive post data, just not to the ErrorDocument 404 /index.php that I've been sending it to. This is what I've been using to prevent a 404 page when parsing the URL to send to the controller.

Any help would be much appreciated!

  • 写回答

1条回答 默认 最新

  • duanhuizhe6767 2015-11-21 00:53
    关注

    If you are having the same problem I did, and nothing else seems to work, it could be that the apache module rewrite "mod_rewrite" is not active.

    Run the command: sudo a2enmod rewrite and restart your apache server: sudo service apache2 restart

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题