$ .post到Codeigniter控制器/方法404找不到页面

时间:2013-09-28 05:18:18

标签: javascript php apache .htaccess codeigniter

我开发了一个Codeigniter原型应用程序,并在开发阶段与Godaddy.com一起托管,用于测试目的而没有问题。此应用程序使用javascript,jquery,HTML5,CSS和PHP(Codeigniter Framework)的组合。本周我已将应用程序转移到客户端服务器并且遇到了许多配置问题,但最终还是碰壁了。

客户端使用PHP5在新的Linux / Apache2服务器上设置全新安装。启用mod_rewrite并将allowoverride设置为all。 Apache2设置(根据客户端)......

Apache2 Configuration

我的.htaccess脚本(因为这个问题我尝试了很多不同的.htaccess版本)......

RewriteEngine On
RewriteBase /CI/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

我将用于将序列化表单数据发布到PHP页面的javascript代码...

        $.post('login_ctrl/authenticateuserlogon', $formData, function($responseData)
        {   
            $userAuthentication=$responseData.userAuthentication;

            if ($userAuthentication=='success')
            {
                window.location.href = "student_portal_ctrl";
            }
            else
            {                       
                $('#loginErrDiv').text('Username or Password is incorrect - Please try again.');
                return;
            }

        });         

我的codeigniter文件结构是......

-root /
       /CI
        /application
        /system
        /index.php
        /license.txt
        /.htaccess

当我发布到此控制器/方法时,浏览器输出...

Firebug 404 Not Found Error

----- ----- EDIT

抱歉,忘了包含我的config.php设置,这里是......

 $config['base_url'] = '';
 $config['index_page'] = '';
 $config['uri_protocol']    = 'AUTO'; //I have tested the app using all of codeigniters 
                                      //default URI Protocols

-----编辑#2 -----

这是控制器上接收404错误的方法

    //AUTHENTICATE USER LOGIN FUNCTION
public function authenticateuserlogon()
{
    //SETTING $FORMDATA TO SERIALIZED POST DATA
    $formData = $this->input->post();

    //Sets the Method for the login_mdl
    $modelMethod=$formData['modelMethod'];

    //LOADING USER AUTHENTICATION LOGIN MODEL
    $this->load->model('login_mdl');


    //SENDING FORMDATA TO MODEL AND RETURING DATA TO $RESPONSEDATA
    $responseData = array();
    $responseData = $this->login_mdl->$modelMethod($formData);

    //OUTPUTTING JSON RESPONSE DATA BACK TO JAVASCRIPT          
    $this->output->set_output(json_encode($responseData));          
}

1 个答案:

答案 0 :(得分:3)

使用经过我测试并且工作正常的.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /CI/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule> 

并在config.php文件中使用此

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
相关问题