Search code examples
php.htaccesscodeignitercodeigniter-routing

Multiple apps Codeigniter: remove "index.php/controller" from URL


I am new to CodeIgniter and trying to understand the basics and maybe some advance methods to set an MVC based application. After a while I thought i might get a try to set a admin panel as well and created and second folder as admin application.

This is my folder structure:

www.domain.com
    --frontend
    --admin

In each folder is an app set with it's own .htaccess file. Bellow is the .htaccess file for admin side.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /admin/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]    
</IfModule>

Current working url is www.domain.com/admin/index.php/admin/posts and I am trying pointless to change it to www.domain.com/admin/posts. So how do I remove the /index.php/admin from url.

The $config['base_url'] is set accordingly for each side(admin/frontend) and the default index.php is set null also , $config['index_page'] = '';

Is this the problem cause I have 2 different apps or just a bad configuration? What is the best practice with multiple applications same site?

Hope i did not duplicated any post and if so please don't hate and try to help me. I am deeply grateful to all of you.


Solution

  • Try this

    in config.php

    $config['base_url'] = '';
    $config['index_page'] = '';
    

    in .htacess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 
    </IfModule>
    

    EDIT 01

    <link href="<?php echo base_url(); ?>css/style.css" rel="stylesheet" />