2

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

客户端使用 PHP5 在新的 Linux/Apache2 服务器上设置全新安装。mod_rewrite 已启用,并且 allowoverride 设置为 all。Apache2 设置(每个客户端)...

Apache2 配置

我的 .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 未找到错误

- - -编辑 - - -

抱歉,忘记包含我的 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));          
}
4

1 回答 1

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'];
于 2013-09-28T05:51:09.817 回答