EllisLab text mark
Advanced Search
2 of 2
2
   
.htaccess for admin panel
Posted: 16 October 2012 09:42 AM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Joined: 2009-01-20
59 posts

I am using HMVC and my structure looks like:

Applications
  Modules
  admin/
    controllers
    views
    models

  frontend/
    controllers
    views
    models

So basically in routes.config I have default website = frontend/front_controller and $route[‘admin’]= ‘admin/backend_controller’

With HMVC you will have modular structure without any .htacces or php file which will route from one location to another. The only .htaccess I have is posted above and it’s just to hide index.php

 
Posted: 16 October 2012 11:44 AM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Joined: 2010-07-20
74 posts

Okkkkk I understood what you meant by not naming the folder as /admin Aken !
Folder structure :

/administrator/
    /
cache/
    /
config/
    /
controllers/
    /...
/
site/
    /
cache/
    /
config/
    /
controllers/
    /...
/
system/
    /...
/
www/
    /...
/.
htaccess
/index.php
/admin.php 

/admin.php

$application_folder 'administration'

/site/config/config.php AND /administrator/config/config.php

$config['base_url''';

$config['index_page''';

$config['uri_protocol''AUTO'

And kept the same .htaccess you gave me.

Accessing http://localhost/muki/admin throws me a 404

But, when I change URI_PROTOCOL to PATH_INFO or QUERY_STRING or ORIG_PATH_INFO, i got my login form displayed, without any style, although the called CSS localhost/muki/www/admin/css/screen.css is the correct path. Don’t know if this can help you to find out the issue.
Think we’re not too far from the solution.

 
Posted: 16 October 2012 04:30 PM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

If you have static assets in an /admin/ folder, you’ll need to add the same RewriteCond conditions that the index.php rewrite rule has to above the admin RewriteRule. Read the comments in the .htaccess example I gave you.

 
Posted: 16 October 2012 05:01 PM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Joined: 2010-07-20
74 posts

Ok thanks, I’ll take a look at that.
And what URI_PROTOCOL should I use, and why ? What does it impact ?

 
Posted: 16 October 2012 05:46 PM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

Use whichever one makes your app work. It can vary by hosting environment. It impacts how CodeIgniter figures out what the current URL is.

 
Posted: 17 October 2012 05:20 AM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2010-07-20
74 posts

Finally made it !
Here’s my full code and folder structure :

/back// admin application
    
/cache/
    /
config/
    /
controllers/
    /...
    /.
htaccess
/front// public site application
    
/cache/
    /
config/
    /
controllers/
    /...
    /.
htaccess
/system// CI system core
    
/core/
    /
database/
    /...
/
www/  // Static assets
    
/back/
        /
css/
        /
img/
        /
js/
    /
front/
        /
css/
        /
img/
        /
js/
/.
htaccess
/admin.php // Routing to /back/
/index.php // Routing to /front/ 


/.htaccess

<IfModule mod_rewrite.c
    
RewriteEngine on
  
    
# Admin URLs
    
RewriteRule ^admin(/.*)?$ admin.php/$1 [L,QSA]
  
    
# Public website
    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteCond 
$!^(img|css|js)
    
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

<
IfModule !mod_rewrite.c>
    
ErrorDocument 404 index.php
</IfModule


/admin.php

...
$application_folder 'back'


/index.php

...
$application_folder 'front'


/back/config/config.php

...
$config['index_page''admin';
$config['uri_protocol''PATH_INFO'


/front/config/config.php

...
$config['index_page''';
$config['uri_protocol''AUTO'


Thanks a lot for helping guys ! raspberry

 
2 of 2
2