1

For a new project what are the steps to link external css, js, images in codeigniter

My Folder Structure is css -> style.css js ->

I have web application, considering internet resources I did

(1) Add the URL for autoload.php

$autoload['helper'] = array('url', 'file', 'text', 'form','string', 'download', 'html', 'security', 'cookie');

(2)Add the base URL in config.php File

$config['base_url'] = 'http://localhost:60/hostel';

(3)Remove index.php from config.php

$config['index_page'] = '';

(4)In my view file I added style

<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url(); ?>css/style.css">

(5)Created a .htaccess file for the project and added

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteCond $1 !^(index\.php|CSS|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

(6) In Application Folder .htaccess file I added

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

I want to linke the style, js files and images. But It is get an error

http://localhost:60/hoste/css/style.css net::ERR_ABORTED 404 (Not Found)
2
  • where are you putting css, image and js. exact directory path Commented May 12, 2019 at 7:06
  • It is in application->css->style.css Commented May 12, 2019 at 7:07

1 Answer 1

2

Don't put them in application directory just create a assets directory in your project root directory. assets/css, assets/images, assets/js

<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url(); ?>assets/css/style.css">
Sign up to request clarification or add additional context in comments.

1 Comment

I did not previous error but now: Resource interpreted as Stylesheet but transferred with MIME type text/html: "localhost:60/dashboard"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.