Set up the base url in codeigniter
In Config.php
$config['base_url'] = 'http://localhost/Appsite/website/';$config['index_page'] = '';# If online site# $config['base_url'] = 'http://stackoverflow.com/';
In .htaccess
(outside application folder) - To remove index.php
in URL
RewriteEngine onRewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?/$1 [L,QSA]
To accessing URL
<a href="<?php echo base_url();?>contollerName/methodName"> click here</a>
To access image
<img src="<?php echo base_url();?>images/images.PNG”>
To access CSS
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css"/>
To use base_url
load URL helper from autoload.php
In your config.php
set the base_url()
as,
$config['base_url'] = 'http://localhost/projectname/';
In your view load the image as,
<img src="<?php echo base_url();?>images/images.PNG”>
Just put this it will take the automatically correct path of the project and set base URL
$site_url = ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http';$site_url .= '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');$site_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);$config['base_url'] = $site_url;