0
votes

I have two codeigniter installations under my public_html folder on my server. One is directly under public_html and the other is under public_html/posts_receive.

The instance under public_html is working normal but when I try to access the codeigniter controller inside public_html/posts_receive it shows:

404 Page Not Found

tried url http://www.example.com/posts_receive/index.php/dashboard

To solve this problem I have added an .htaccess file under public_html/posts_receive which contain the following:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /posts_receive
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>

My controller is named dashboard.php and contains the following:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard extends CI_Controller {


    public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));

        $this->load->library("pagination");
    }

    public function index() {
        $config = array();

        $data['link_sel']='dashboard';
        $data['stats']=$this->fetch_stats();
        $this->load->view("header_inc", $data);
        $this->load->view("dashboard", $data);
        $this->load->view("footer_inc", $data);
    }   
}
?>

config.php includes:

$config['base_url'] = 'http://www.example.com/posts_receive/';
$config['index_page'] = 'index.php';
2
Did you try http://www.example.com/posts_receive/dashboard ? can you post the outcome of this? - Rajesh
Ya i tried the same it showing the same error,no changes - Boopathi N
is it the same thing even when you remove the htaccess? - Rajesh
Beginning itself it shows the error as file not found.I referred some guide.So i added .htaccess. But again it showing the same error. - Boopathi N

2 Answers

2
votes

You should run both applications from one CodeIgniter base. You will have 2 sub folders in your application folder. Take a look at the documentation: https://www.codeigniter.com/userguide3/general/managing_apps.html

From there on you can create the same index.php file as in your root in your posts_recieve folder and point it to the right application directory. That is how i managed to do it. Otherwise the CodeIgniter instance in your root will think you are navigating to a controller called posts_recieve which does not exists in that application.Hope this helps. Otherwise, just ask when things are unclear.

0
votes

Inside .htaccess, RewriteBase /posts_receive part is not needed.

RewriteRule ^(.*)$ index.php?$1 [L]

should become

RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

(<IfModule mod_rewrite.c> is a server configuration condition. It means you should have mod_rewrite module installed and active on the web server for these settings to work.)

You could leave empty $config['index_page'] inside config.php:

$config['index_page'] = '';

And you can call the controller without the index.php part:

http://www.example.com/posts_receive/dashboard