0
votes

i have the following problem..

I've created themain codeigniter website which is located in sub.domain.com and i've also created another codeigniter application (the admin) in sub.domain.com/admin..

*Note that i 'm not using HMVC model, in case someone mentions it...

The thing is that when i'm trying to access the /admin url i get a error 404 redirect problem.

Here are my main files and some extra things i shall mention:

.htaccess file:

Options -Indexes
Options +FollowSymLinks

# Indexes default
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /admin
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php/$1
</IfModule>

My routes.php file:

/**
* Users login - logout
*/
$route['login'] = 'users/users/login';
$route['logout'] = 'users/users/logout'; //Controller located in subfolder

$route['users'] = 'users/users';
$route['users/(:any)'] = 'users/users/$1';
/**
* Redirect any URI after default url
*/
$route['pages/(:any)'] = 'pages/$1';

/**
* Other routes
*/
$route['(:any)'] = 'pages';
$route['default_controller'] = 'pages';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

I also have this in my header.php file in which i redirect the user in login if not logged in etc.. etc..

if (!$this->ion_auth->logged_in() && $this->uri->segment(1) !== 'login') {              
    redirect('login');
} elseif( $this->ion_auth->logged_in() && !$this->ion_auth->is_admin($this->ion_auth->get_user_id()) ){
    redirect('logout');
}

The application/controllers structure is like:

Controllers
-Customers
--Customers.php
-Users
--Users.php
-Pages.php
etc..etc..

I've tried everything (.htaccess, RewriteBase /admin etc..) but still nothing works..

Any ideas? Thanks...

1
You wrote that you have the main application and another application - this can be done in different ways, and the answer depends on it. Please, show your folder and files structure on upper level (when folders application, system, www, e.t.c). Folder 'admin' = 'application' folder, other 'project' or folder/controller in main application? - Elena Vasilenko
@ElenaVasilenko Under sub.domain.com the structure is: (admin, application, assets, system, .htaccess, etc.. etc..) and under sub.domain.com/admin the structure is: (application, assets, system, .htaccess etc.. etc..) If that's what you mean! - Citer
Yes, that's what I mean. My decision below in the Answer. - Elena Vasilenko

1 Answers

0
votes

Try this:

.htaccess in main application:

AddDefaultCharset UTF-8
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)admin(.*)$ /admin/index.php$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php/$1
</IfModule>

.htaccess in /admin:

AddDefaultCharset UTF-8
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) /admin/index.php/$1
</IfModule>