0

Hi This is my website link http://webscarlets.com/ci/welcome

I'm new to codeigniter. I removed the index.php from the url. To remove the index.php from url i used the following code. I get this code from the codeigniter user guide

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

But the css is not loading. Here is my configuration settings

//autoload.php
$autoload['helper'] = array('url','form','html');

//config.php   
$config['base_url'] = 'http://webscarlets.com/ci/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

//constants.php
define("LAYOUT_URL","http://webscarlets.com/ci/");

//view.sphp 
<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URL; ?>css/all.css">

Please review my codes and guide to complete this task.

Thanks to all in advance.

1
  • first of all echo the base_url() so that you can sure about the URL. Commented Aug 6, 2012 at 10:55

2 Answers 2

2

At the moment css link is http://webscarlets.com/ci/application/css/all.css so make sure there is css files is placed on this path or put css file on root folder and use <link rel="stylesheet" type="text/css" href="<?php echo base_url; ?>css/all.css"> instead of Layout url.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply. It's working great. Now if i want to put the css, images into application folder means what should i do?
Put the images folder on same directory where css folder is placed and use these images like images/abc.jpg in the css clsss
Placing the images and css files in the root folder is the healthy way to program in codeigniter? Because i don't about these. i'm a beginner
ya there is no problem in this...It will work without any problem....In case this answer helps you, you can upvote or accept this answers to make it easy for all users
1

As you ask in your question, you want to remove the index.php string in the url, so in .htaccess file you will have something similar to:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Also you say you have your css in

css/all.css

To allow CI to load the css you must permit it in .htaccess file, adding the folder that you don't want to be rewrited. In your case, and supposing that your all.css file is in css folder you must write the next .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt|css)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

In other hand, if you will going to store the css file in other dir, for example assets, you must be sure you added that in .htaccess file.

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|robots\.txt|css)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

And remember that's all I said to you can be applied to images, js or css. Only remember to add the folder where are stored to .htaccess file.

Once you do that, you can add the css in your view using the base_url() helper or writing directly

<link rel="stylesheet" type="text/css" href="/ci/css/all.css">

Please be careful about where is located your CI app.

I hope it will help you. Good luck!

Comments

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.