Clannad System
Clannad System

Reputation: 489

How to make Routes work in Multiple CodeIgniter Applications?

Structure of CodeIgniter App

www.domain.com - /assets - /system

portal.php      ( portal application index page )

members.php     ( members application index page )

admin.php       ( admin application index page )

products.php    ( products application index page )

URLS of INDEX ( working )

http://www.domain.com/portal.php <--------- working

http://www.domain.com/members.php <--------- working

http://www.domain.com/admin.php <--------- working

http://www.domain.com/products.php <--------- working

ROUTES

members routes.php

$route['mem/display_list'] = "members/get_list";  

portal routes.php

$route['por/display_list'] = "portal/get_list";  

admin routes.php

$route['adm/display_list'] = "admin/get_list";  

products routes.php

$route['prd/display_list'] = "products/get_list";  

URL with controller

http://www.domain.com/portal.php/portal/get_list <----- working

http://www.domain.com/admin.php/admin/get_list <----- working

http://www.domain.com/members.php/members/get_list <----- working

http://www.domain.com/products.php/products/get_list <----- working

Question : How Can I Make it Work with routes..

http://www.domain.com/mem/display_list <----- NOT working

http://www.domain.com/por/display_list <----- NOT working

http://www.domain.com/adm/display_list <----- NOT working

http://www.domain.com/prd/display_list <----- NOT working

Is it about configuring multiple index.php in .htaccess file?

Upvotes: 3

Views: 2061

Answers (4)

this structure of files (multi application):

- application
    - admin
    - site
- system
- index.php
- admin.php

Your rewrite rule is wrong if you want /admin to rewrite to admin.php, with your current rule it will result in /index.php/admin.

You didn't mention if that's the problem, if it is do this:

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

Also you can debug the rewriting using RewriteLog: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

If that doesn't fix it please describe the current behaviour and what you expect, otherwise it's difficult to help.

Upvotes: 0

ultimate
ultimate

Reputation: 658

The only possible answer I see is to have multiple .htaccess files. One on the the root and one for every individual application. This way you can get mod_rewrite to work for you.

Upvotes: 0

Bhavik Patel
Bhavik Patel

Reputation: 613

We also facing same issue regarding index.php so we have solution like this : You can use .htaccess file like

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

we have index.php so you use your filename.php and skip this file name in url so your URL is working fine with your requirement.

Upvotes: 0

iivannov
iivannov

Reputation: 4411

CodeIgniter is always using the index.php (in your case: portal.php, members.php, admin.php, products.php).You will have to direct every request to the right .php file.

So the solution will be to add RewriteRules for each of them in the .htaccess file.

I have not tested it but I suppose something like this will do the work:

RewriteRule ^mem/(.*)$ members.php/$1 [L]

And of course for all the others:

RewriteRule ^por/(.*)$ portal.php/$1 [L]

RewriteRule ^adm/(.*)$ admin.php/$1 [L]

RewriteRule ^prd/(.*)$ products.php/$1 [L]

Upvotes: 2

Related Questions