Search code examples
phpcodeigniterurl-rewritingcodeigniter-2

Not Found The requested URL /singlecodebase/Feb152017/login was not found on this server


Login Page shows up but on login I am getting the error Not Found

The requested URL /singlecodebase/Feb152017/login was not found on this server. Is it something to do with httpd.conf file? I am using Digital ocean as my cloud server. The code uses CodeIgniter version 2

My .htaccess file is as below

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

My login Controller is: login.php

<?php
class login extends CI_Controller
{
    var $data;

    function  __construct() {
        parent::__construct();
        $this->load->helper('cookie');  
        $this->load->library('session');
        $is_admin_logged_in = $this->admin_init_elements->admin_logged_in_status();  
        global $USER;
        if($is_admin_logged_in == TRUE){
            redirect('home');
            //;
        }

        //populate viewfor header / footer elements

        $this->admin_init_elements->init_elements('N');
        $this->load->model('mod_login');

    }

    function index(){
        //if Admin already logged in, send to Admin home

        $this->data['message']='';
        $this->data['msg_class'] = '';
        $post_array=$this->input->post();

        $data['old_images']=$this->mod_common->getBgImages();

        if($this->input->cookie('remember') == 'on')
        {
            //echo $this->input->cookie('username');
            $this->data['message']=strip_tags($this->mod_login->check_cookie_login());
            if($this->data['message']=='Login Successful'){
                $this->data['msg_class'] = 'sukses';
                 redirect('home');              
            }else{
                $this->data['msg_class'] = 'gagal';
            }
        } 
        if($this->input->post('action')=='adminLogin'){

        //print_r($this->input->post()); die;

            if(isset($post_array['remember'])){
                $username_cookie= array(
                    'name'   => 'uusername',
                    'value'  => $post_array['username'],
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $password_cookie= array(
                    'name'   => 'userpass',
                    'value'  => $post_array['userpass'],
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $remember_cookie= array(
                    'name'   => 'remember',
                    'value'  => 'on',
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $this->input->set_cookie($username_cookie); 
                $this->input->set_cookie($password_cookie); 
                $this->input->set_cookie($remember_cookie); 
                //die;

            }
            else
            {
                if($this->input->cookie('remember') == 'on')
                {
                    if($this->input->cookie('uusername') != $post_array['username'])
                    {
                        delete_cookie("remember");
                        delete_cookie("uusername");
                        delete_cookie("userpass");
                    }
                } 
            }

            $this->data['message']=strip_tags($this->mod_login->validate_admin_login());
            if($this->data['message']=='Login Successful'){
                $this->data['msg_class'] = 'sukses';
                $companyName = $this->input->post('company');
                //echo $companyName;
                //$this->session->set_userdata($companyName);
                $this->session->set_userdata(array(
                    'company'  => $companyName              
                ));
                //$this->load->database($companyName, TRUE);
                //print_r($this->session->userdata); 
                //die;
                 redirect('home');              
            }else{
                $this->data['msg_class'] = 'gagal';
            }
        } /*else if(isset()){

        }*/


    ///////////////////////
        $this->data['cookieRemember'] = $this->input->cookie('remember');
        $this->data['cookieUsername'] = $this->input->cookie('username');
        $this->data['cookiePassword'] = $this->input->cookie('userpass');
        //echo $this->data['cookieRemember'];echo $this->data['cookieUsername']; echo $this->data['cookiePassword'];
    //////////////////////

        $this->data['cookiename']  = $this->input->cookie('name', false);
        $this->data['cookieimage'] = $this->input->cookie('image', false);

        $sess_msg = $this->session->userdata('session_msg');
        $session_msg_class = $this->session->userdata('session_msg_class');
        if(isset($sess_msg) && $sess_msg!= ''){
            $this->data['message']=$sess_msg;
            $this->data['msg_class'] = $session_msg_class!=''?$session_msg_class:'gagal';
        }
        //render full layout, specific to this function
        $this->load->view('login', $this->data);
    }

////////////////////////////////////////////////////////////////////////////////    
    function forgot_password(){
         $this->load->view('send_reset_link', $this->data);
    }

    function send_pass_reset_link(){

        $post_array=$this->input->post();
        if($post_array['email']!='') { 
        $email_id=$post_array['email'];

        $user_id=$this->mod_common->get_userid($post_array['email']);

        foreach($user_id as $key){
            $id=$key['id'];
        }

        if($id>0){

        $link=base_url().'login/reset_password/'.$id;
        $message_body="<table>
                        <tr><td style='padding:10px 0px'>Dear User,</td></tr>
                        <tr><td style='padding:10px 0px'>You have received this communication in response to your request to reset your online portal account password. Please find below the link to reset your password</td></tr>
                        <tr ><td style='padding:10px 0px'><a href='".$link."' style='background:#86c337;text-decoration:none;padding:5px 10px;color:#fff'> Reset Password </a></td></tr>
                        <tr ><td style='padding:10px 0px'>Regards,<br>Unfold</td></tr>

                       </table>";

        /*-------------------------*/
        //sending pass reset mail 
        $this->load->library('email');
        $config['protocol']     = 'sendmail';
        $config['mailpath']     = '/usr/sbin/sendmail';
        $config['charset']      = 'iso-8859-1';
        $config['wordwrap']     = TRUE;
        $config['mailtype']     = 'html'; 
        $this->email->initialize($config);

        $this->email->set_newline("\r\n");
        $this->email->from("info@unfold.com","Admin");//email id and name of the sender
        $this->email->to($email_id); // email id of the recipient
        $this->email->subject("Reset Password"); //The subject line
        $this->email->message($message_body);
        $this->email->send();
        //$this->email->clear();
        //show_error($this->email->print_debugger());
        //die;
        /*-------------------------*/
        $this->data['reset_link_msg']="An email with the password reset link has been sent to your mail address.";
     }else{
        $this->data['reset_link_msg']="Sorry! The email entered is not in our database.";
     }  
        } else {$this->data['reset_link_msg'] = '';}

        $this->load->view('send_reset_link', $this->data);

    } 

    function reset_password(){
        if($this->input->post()){   

            $post_array=$this->input->post();
            $this->data['reset_msg']=$this->mod_common->reset_password($post_array);
            $this->load->view('reset_password', $this->data);
        }

        if($this->uri->segment(3)!=''){
         $this->data['id']=$this->uri->segment(3);
         $this->load->view('reset_password', $this->data);
        }
        else{
            redirect('login');
        }
    }










    // Admin authentication ----------
}

?>

Solution

  • your .htaccess seems OK but the problem is from appache

    please try to run this command:

    sudo a2enmod rewrite