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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题