2
votes

I have created application in codeigniter.Both Front end and Back end.

My Folder Structure is

Pariwar -> Root

 ----  css 
 ----  js
 ---admin
             ---- .htaccess
             ----  index.php
             ----  css 
             ----  js

 --application
              ----admin
                     ----   views
                      =---  models
                      ----  controllers
              ----Front
                        ----   views
                      =---  models
                      ----  controllers

I have created the structure using http://webduos.com/create-an-admin-panel-with-codeigniter/.

when I accessing Front end using http://localhost/Pariwar/ all working fine.

But when I trying to accessing back-end using http://localhost/Pariwar/admin/ the css and js are not loading and showing error.

I have set $config['base_url'] = 'http://localhost/Pariwar/'; for Front End $config['base_url'] = 'http://localhost/Pariwar/admin/'; for back end.

Also made proper changes in index.php file.

Also my .htaccess file is

RewriteEngine on RewriteCond $1 !^(index.php|images|css|fonts|js|uploads|upload|img|floorplan|mainslider|projectslider|robots.txt) RewriteRule ^(.*)$ http://localhost/Pariwar/index.php/$1 [L] for front folder

And

RewriteEngine on RewriteCond $1 !^(index.php|images|css|fonts|js|uploads|upload|img|floorplan|mainslider|projectslider|robots.txt) RewriteRule ^(.*)$ http://localhost/Pariwar/admin/index.php/$1 [L] for admin.

Please help me to solve this issue.

2

2 Answers

1
votes

You need to place all those css and js files within root folder only from there you can access your files within codeigniter

--application
--system
--admin
--public

   --js

   --imgs

   --css

Then using a helper function as:

application/helpers/utility_helper.php:

function public_url(){
   return base_url().'public/';
}

and within your application/config/autoload.php:

$autoload['helper'] = array('url','utility');

You will then have access to asset_url() throughout your code.

0
votes

You only need one .htaccess file at the root of your application. The second .htaccess file in the admin folder is assuming that there is an admin sub-folder within the admin folder.

Create one .htaccess file at the root of your applications and set your rules here.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder.
    #Additionally this will allow you to create a System.php controller,
    #‘system’ can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn’t true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #This last condition enables access to the images and css folders, and the 
    robots.txt file
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

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

Consider reading up on mod_rewrite documentation to learn more about Apache mod_rewrite rules