我在MVC框架上建立一个CMS我也在建设,但我已经被困在这里了。完整代码可在this link to github找到。
好的,我遇到的问题是这个.htaccess文件:
<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>
当我在&#34; auth / login&#34;上运行代码时通过这个ajax请求:
$.ajax({
type: "POST",
url: "auth/login",
dataType: "json",
data: { username: username, password: password, token: token_value }
})
当我跑步时:
$username = $_POST['username'];
$password = $_POST['password'];
$token = $_POST['token'];
$postdata = array('username' => $username, 'password' => $password, 'token' => $token);
print_r($post_data);
print_r($_SERVER);
我明白了:
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
)
我知道上面的代码块有效,因为我已经在静态&#34; test.php&#34;上尝试了它。文件,它输出此ajax请求提交的用户名/密码/方法信息。
我真的觉得这个问题存在于我的.htaccess文件中,因为当我强行使用200 OK标题时,它仍然认为它是404或者什么?我不确定但它擦洗了$ _POST。这个问题与我的php.ini或apache2.conf没有关系,因为我已经测试过了,我能够接收发布数据,而不是ErrorDocument 404 /index.php我一直把它送到。这是我在解析要发送给控制器的URL时用来阻止404页面的。
非常感谢任何帮助!
答案 0 :(得分:0)
如果你遇到了同样的问题,似乎没有其他任何工作,可能是apache模块重写&#34; mod_rewrite&#34;不活跃。
运行命令:sudo a2enmod rewrite
并重新启动您的Apache服务器:sudo service apache2 restart