Question

I'm trying to develop a little base CMS with CodeIgniter for my own use on projects but got stuck on this. Also, I'm very new to CI, but got some years with ZF and OOP PHP.

First of all let me show you my file structure:

  • index.php (frontend bootstrap)
  • backend.php (backend bootstrap)
  • .htaccess
  • system ( CI core )
    • application
      • backend
        • [...] MVC related files and folders (config, controllers, models, views...)
      • frontend
        • [...] MVC related files and folders (config, controllers, models, views...)
    • codeigniter
    • [...] (cache, database, scaffolding...)

Ok. I can get to work the index.php or backend.php routing with an .htaccess, but can't get it to work with both. Here's the .htaccess code:

RewriteEngine on
RewriteBase /

# Hide the application and system directories by redirecting the request to index.php (and throwing a 404 error)
RewriteRule ^(application|system|\.svn) index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

Well, what I need is the following:

  • www.domain.com/backend/controller/action/parameters (backend.php routing)
  • www.domain.com/controller/action/parameters (index.php routing)

Hope I explained well.

Can anyone help, please? :)

Best regards.

Was it helpful?

Solution

After some more searching, I've found a very nice article documenting how to do what I need. It also explains the 3 ways to backend/frontend in CI:

  • separate applications
  • sub-directories
  • HMVC (Hierarchical Model View Controller)

HMVC fits my needs perfectly, but i'll give a try to sub-directories first. :)

OTHER TIPS

Basically you want to run two CodeIgniter applications side by side, one in the root and one in backend/. There are a few ways to do this, but the simplest is to add a rewrite rule for your second instance (removing the Last flag):

RewriteRule ^backend/(.*)$ /backend/index.php/$1 [QSA]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top