i am getting this type of url when trying to access pages other than index page
http://localhost:8012/health-care/8012//localhost/health-care/index.php/index.php/home
but url to access page must be
http://localhost:8012/health-care/index.php/home
my problem in url is: "it is duplicating url after "i hhttp://localhost:8012/healthcare/ that should not be duplicated.
i have autoloaded url helper in autoload.php as well as manually in constructor of controller. my base_url in conf
$config['base_url'] = 'http//localhost:8012/health-care/index.php/';
Guide me about this problem.
in addition to tell you that i have two app fron one codeigniter i.e. frontend and backend.
Url for backend works properly but for frontend its giving me mistakes what to do ?
$config['base_url'] = 'http//localhost:8012/health-care/';
used this base url you getting this url
http://localhost:8012/health-care/index.php/home
Y0u have to change this line
http://localhost:8012/health-care/index.php/home
to this
$config['base_url'] = 'http//localhost:8012/health-care/';
Please have a try.
Try this code:
$config['base_url'] = 'http://localhost:8012/health-care/';
and also make index_page as empty like this:
$config['index_page'] = '';
.htaccess file was not working. just replaced file and my problem got solved.
I am working on a project in codeigniter. I have stuck in baseurl when I run the controller then it includes all the files of jquery and css. But when I run a function then the url of the jquery add the name of the controller.
This is my base url: $config['base_url'] = 'http://localhost/cod_login/';
I don't know why codeigniter is doing that.
Base URL is wrong. It should be like this
$config['base_url'] = 'http://localhost/cod_login/';
$config['base_url'] = 'http://localhost/poject_name'; # syntax
$config['base_url'] = 'http://stackoverflow.com/'; # example
In Routes
$route['default_controller'] = "defult_controler_name";
$route['404_override'] = '';
this is happen when you don't echo base URL only (echo) is missing thanks to all for ans
set dynamic base url on on live in ci
$config['base_url'] = 'http://localhost/demo';
when i upload it on live and when live url changes the url is automatically need to change on live ,help me
You could use it like this -
In localhost :
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/foldername/";
Just be sure in live if you are using subdomain then it would be like this -
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/subdomainfolder/";
if your files are in root then it should be :
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/";
Please check it and revert if not solved.
Codeigniter is a first for me so I hope I am clear in my explanation. In this case, I am dealing with setting up a Codeigniter website on a different server. I was getting forbidden access errors but have since corrected this, I think.
I've worked out the base url in config file to:
$config['base_url'] = 'http://websitename.com/';
and index_page is:
$config['index_page'] = '';
with the uri as:
$config['uri_protocol'] = 'AUTO';
The links from the menu are not redirecting properly. They simply reload the index page. In Firebug, this is what I see as one of the page links:
https://websitename.com/index.php?module/rekap_tl
Perhaps this is enough to understand the trouble here. I am working with this on a live server.
Any and all help is greatly appreciated.
you can configure codeigniter like
$config['base_url'] = ''; // Leave it empty so that codeigniter can guess it by itself, set $config['index_page'] = 'index.php'; and $config['uri_protocol'] = 'AUTO'; after that open application/config/autoload.php and then add url helper class to autoload helper $autoload['helper'] = array('url'); after that you can use in you menus "<?php echo base_url(); ?>index.php/controller/method/args" hope this may help
when I had my site on development environment - it was url: testurl.com
Now on production server my codeigniter app's address has to be someurl.com/mysite/
I moved it there, and everytime I'm trying to run some function, example /home/test - it gets me into someurl.com/home/test - which is WRONG.
It has to be someurl.com/mysite/home/test - How to fix it? I did set
$config['base_url'] = someurl.com/mysite/
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
Check
config > config
codeigniter file structure
replace
$config['base_url'] = "your Website url";
with
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
Well that's very interesting, Here is quick and working code:
index.php
/**
* Define APP_URL Dynamically
* Write this at the bottom of index.php
*
* Automatic base url
*/
define('APP_URL', ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['SERVER_NAME']}".str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']));
config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = APP_URL;
CodeIgniter ROCKS!!! :)
If you leave it blank the framework will try to autodetect it since version 2.0.0.
But not in 3.0.0, see here: config.php
I think CodeIgniter 3 recommends to set $config['base_url'] to a full url manually in order to avoid HTTP header injection.
If you are not concerned about it, you can simply add the following lines in your
application/config/config.php
defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
In this way you also have BASE_URL constant available in all your project code (including the views) and you don't have to use functions:
config_item('base_url') //returns BASE_URL
$this->config->item('base_url'); //returns BASE_URL
After declaring the base url in config.php, (note, if you are still getting the same error, check autoload.php)
$config['base_url'] = "http://somesite.com/somedir/";
Check "autoload"
CodeIgniter file structure:
\application\config\autoload.php
And enable on autoload:
$autoload['helper'] = array(**'url',** 'file');
And it works.
this is for server nd live site i apply in hostinger.com and its working fine
1st : $config['base_url'] = 'http://yoursitename.com'; (in confing.php)
2) : src="<?=base_url()?>assest/js/wow.min.js" (in view file )
3) : href="<?php echo base_url()?>index.php/Mycontroller/Method" (for url link or method calling )
application > config > config.php
search for $config['base_url'] and put your site like "//example.com" (skip protocol)
$config['base_url'] = "//someurl.com/";
This works for me.
You may use default base URL path for any server
That have to used in config folder > config.php files
replace you :
$config['base_url'] = 'index.php';
by this code:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#','',dirname($_SERVER['SCRIPT_NAME'])).'/';
it's auto found your folder form any server
In your config file, leave the $config['base_url'] = ''
base_url will automatically create one. In your Codeigniter system/core/Config.php
// Set the base_url automatically if none was provided
if (empty($this->config['base_url']))
{
if (isset($_SERVER['SERVER_ADDR']))
{
if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE)
{
$server_addr = '['.$_SERVER['SERVER_ADDR'].']';
}
else
{
$server_addr = $_SERVER['SERVER_ADDR'];
}
$base_url = (is_https() ? 'https' : 'http').'://'.$server_addr
.substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
}
else
{
$base_url = 'http://localhost/';
}
$this->set_item('base_url', $base_url);
}
This code is already there to automatically create the base URL and protocol.
Thanks.
Do you miss Double quotation marks?
$config['base_url'] = "someurl.com/mysite"
Dynamic Base Url (codeigniter)
Just overwrite the line in config/config.php with the following:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/project_name/";
this way you config you base_url , then won't worry about in hosting. both works in localhost and server.
Base url set in CodeIgniter for all url
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";
Base URL should be absolute, including the protocol:
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/mysite/";
This configuration will work in both localhost and server.
Don't forget to enable on autoload:
$autoload['helper'] = array('url','file');
Then base_url() will output as below
echo base_url('assets/style.css'); //http://yoursite.com/mysite/assets/style.css
Change in config.php like this.
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://". #$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;
Try to add the controller to your index page aswell. Just looked at as similar structure on one of my own site and I hade my base url set to = "somedomain.com/v2/controller"