How to Set Proper Codeigniter Base Url

How to set proper codeigniter base url?

Base URL should be absolute, including the protocol:

$config['base_url'] = "http://somesite.com/somedir/";

If using the URL helper, then base_url() will output the above string.

Passing arguments to base_url() or site_url() will result in the following (assuming $config['index_page'] = "index.php";:

echo base_url('assets/stylesheet.css'); // http://somesite.com/somedir/assets/stylesheet.css
echo site_url('mycontroller/mymethod'); // http://somesite.com/somedir/index.php/mycontroller/mymethod

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 on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 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

How to Properly set base_url() in codeigniter?

Use this:

<link rel="stylesheet" href="<?php echo site_url(); ?>assets/front/website/static/fonts/icomoon-greycom/css/style.css">

How to set config_base url in config.php file in codeigniter?

You should got to this file path

Codeigniter/applications/config/config.php

Search for this line that contains

$config['base_url'] = ""

Then your base_url should be

$config['base_url'] = "http://yoursite.com/"

If xampp, it should be

$config['base_url'] = "http://localhost/yoursite/"

And if wamp, it should be

$config['base_url'] = "http://www/yoursite/"

Note that yoursite is the filename of the site folder you have in htdocs or www folder

When you make use of <?php echo base_url(directory/file_name); ?> In your views, it should output something like:

 "http://localhost/yoursite.com/directory/file_name"

That should do the trick

Codeigniter how to properly use base_url?

You can assign base_url dynamically using host

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';

Base_url() not working on codeigniter

in config.php set this line

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

root directory set this way

application
system
bootstrap-3.3.6


Related Topics



Leave a reply



Submit