php - Base url is not working

595

When i use base_url as

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

It redirects to localhost/login/validate and shows object not found. Any idea why? But it works perfectly in live server when i set base_url to domain.

$config['base_url'] = 'http://designhub.com.np/educare'; 
51

Answer

Solution:

you can use this code in config.php

$ark_root  = "http://".$_SERVER['HTTP_HOST'];
$ark_root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $ark_root;


$root  = "http://".$_SERVER['HTTP_HOST'];

/*assets path*/
define('HTTP_CSS_PATH', $config['base_url'].'assets/css/');
define('HTTP_DOC_PATH', $config['base_url'].'assets/docs/');
define('HTTP_IMAGES_PATH', $config['base_url'].'assets/images/');
define('HTTP_JS_PATH', $config['base_url'].'assets/js/');
define('HTTP_IMG_PATH', $config['base_url'].'assets/img/');

you can use it local as well as on server too

114

Answer

Solution:

When your on a local host set it some thing like

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

When use live domain

$config['base_url'] = 'http://www.yourdomain.com/';
184

Answer

Solution:

You should write the folder name in which the project files are: (with localhost)

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

As your live server has your project files under root folder like public_html so you can use base_url as you mentioned.

But with local, write folder name afterlocalhost as I have mentioned.

People are also looking for solutions to the problem: php - Remote database connection in codeigniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.