0
votes

i configure website on my local host using XAMPP but other rhan homepage the css files not loding

my .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

config.php

$config['index_page'] = '';
$config['base_url'] = 'http://hypertradeproject.local/';

on home page css link like.

<link rel="stylesheet" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">

when i open page source they are like

http://hypertradeproject.local/assets/css/bootstrap.css

and on all other pages they are like i.e

<link rel="stylesheet" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">

when i open page source they are like

http://hypertradeproject.local/site/cat_one_subcat/assets/css/bootstrap.min.css http://hypertradeproject.local/login/assets/css/bootstrap.min.css

they have to be like

http://hypertradeproject.local/assets/css/bootstrap.min.css http://hypertradeproject.local/assets/css/bootstrap.min.css

im new to codeigniter. any suggestions.

thanks in advance.

4

4 Answers

1
votes

First load url helper in application/config/autoload.php using

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

OR you can load url helper in controller using $this->load->helper('url');

then link your css files like below:

<link rel="stylesheet" href="<?php echo base_url('assets/css/bootstrap.css');?>">
<link rel="stylesheet" href="<?php echo base_url('assets/css/bootstrap.min.css');?>">
1
votes

$config['root_dir']= "/"; Add this line in your application/config/config.php file

then inlcude your css file like this
<link rel="stylesheet" href="<?php echo $this->config->item('root_dir')?>assets/css/bootstrap.css">
<link rel="stylesheet" href="<?php echo $this->config->item('root_dir')?>assets/css/bootstrap.min.css">
1
votes

You can simply add site_url in front of path.

Thanks

0
votes

Its working heres the two diffrent ways.

Either place base_url (base url whic we defign in application/config/config.php) at the start in href like this.

<link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap.css">

or just add "/" start of href like this.

<link rel="stylesheet" href="/assets/css/bootstrap.css">