2

I am beginner in Codeigniter. I have downloaded the software and tried to configure it. How can I configure a base url to use in codeigniter?

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Dipika
  • 115
  • 1
  • 3
  • 15

5 Answers5

3

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

pamekar
  • 729
  • 7
  • 10
1

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";
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
  • This is the best and most complete reply since it is the unique one that mentions the URL helper – Robert Feb 16 '19 at 09:32
0

Go to application/config , open config.php and put value in this variable

$config['base_url'] = '';
Waleed Ahmed Haris
  • 1,229
  • 11
  • 17
0

Note: Following solutions is detailed provided you have setup your localhost on your machine successfully.

Both the points as mentioned above will work. Like, you can set the Base URL value for your corresponding setting of localhost or you can set it to EMPTY.

  1. Setting as Empty (Simple and Elegant)

    $config['base_url'] = '';

The Codeigniter version 2.0.0.0 simply autodetects the base_url of your current project.

But in CI version 3.0.0.0 it's NOT supported anymore. You have to explicitly declare you projects Base URL.

  1. Configuring the path to your Project Directory. The following procedure is when you setup your localhost using xampp in Windows or using default Apache's configuration folder in Linux i.e var/www/html/your_project_directory.

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

  2. Using nginx configuration in Linux or wamp in Windows

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

Mohd Belal
  • 1,119
  • 11
  • 23
0

if you are running your project in local-server like Xamp or wamp then you can set the base url like this $config['base_url']=""; or you can also set $config['base_url']="http://host/yoursite"