CodeIgniter Base URL Configuration

In continuation of CodeIgniter configuration, in this tutorial, we are going to configure Base URL for a web application

CodeIgniter URLs

CodeIgniter URLs use Uniform Resource Identifiers (URI). In simple terms, CodeIgniter’s URLs are simply segments. These segments are then split up and used to load a particular controller and method. Here is a typical CodeIgniter URL:
http://mywebsite.ext/index.php/controller/method/parameters
Everything after the index.php segment is used by CodeIgniter to determine what to load. The first segment is the name of the Controller. The second segment is used to determine which function to load—if this is blank then the index function will be used. The final segment will be used to pass any data to the function.

Config Base URL:

Base URL is your CodeIgniter root. Typically, this will be your Domain name or IP Address, with a trailing slash e.g.  “http://technhit.in/” We can configure Base URL  in the config.php file under application/config directory. Base URL should be absolute, including the protocol:

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

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

If Base URL is not set, then CodeIgniter will try to guess the protocol, domain and path to your installation. However, you should always configure this explicitly and never rely on auto-guessing, especially in production environments. You can configure the base URL in the $config array with key “base_url” as shown below

 <?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://technhit.in/';


<<Previous                                                                          Next>>

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

5 thoughts on “CodeIgniter Base URL Configuration

  1. Pingback: CodeIgniter - Remove Index php from URL - NHIT Tech Blog

  2. o Plant your seeds with each season in mind,
    to ensure regardless of what season it can be, you are going to will have flowers blooming inside your
    garden. It is no wonder until this dish is actually as popular in Northern Europe when compared with its place of
    its origins, which is in Texas and also the New Mexico area as you have a tougher defense mechanisms to
    address cold and harsh environments. The natual skin care information provided
    by dermatologists point for the importance of doing
    all five activities over a daily basis.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.