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 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)