Hello What is the difference between SiteUrl() and BaseUrl() ? In my previous project it is base url but now in my new project it is Siteurl.Why this happens? Is baseurl() is an outdated one
-
Possible duplicate of [what is the difference between site\_url() and base\_url()?](http://stackoverflow.com/questions/17079711/what-is-the-difference-between-site-url-and-base-url) – Nam G VU Nov 09 '15 at 05:17
3 Answers
Base url for Image / script / css path. site url for Address url for accessing the controllers
echo base_url(); // http://example.com/path/to/your/ci/install
echo site_url(); // http://example.com/path/to/your/ci/install/index.php
You can refer this forum:

- 8,810
- 9
- 39
- 58
-
1Here is the ref: http://ellislab.com/codeigniter%20/user-guide/helpers/url_helper.html – Frank Conry Dec 24 '13 at 17:46
-
1What if I remove index.php with .htaccess? Can I use base_url all times? – Lucas Bustamante Mar 04 '17 at 17:06
-
-
@user9437856, if you want to use CI anchor , then have to use `anchor(uri segments, text, attributes)`. Otherwise you can use plain html `a` tag with `site_url()` in href. – Kumar V Jun 11 '18 at 04:30
-
Thanks, @KumarV, So I am using like this . Is it a best practices? – user9437856 Jun 11 '18 at 06:06
To clear all your doubts you have to read CodeIgniter Manual.Please Click Here
base URL
Returns your site base URL, as specified in your config file. Example: echo base_url();
This function returns the same thing as site_url, without the index_page or url_suffix being appended.
Also like site_url, you can supply segments as a string or an array. Here is a string example: echo base_url("blog/post/123");
site URL
Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.
You are encouraged to use this function any time you need to generate a local URL so that your pages become more portable in the event your URL changes.
Segments can be optionally passed to the function as a string or an array. Here is a string example: echo site_url("news/local/123");
The above example would return something like: http://example.com/index.php/news/local/123
Here is an example of segments passed as an array: $segments = array('news', 'local', '123');
echo site_url($segments);

- 199
- 3
- 15
No doubts the answers by kumar_v and nidheesh are absolutely correct . However , I would like to add when to use base_url() and the site_url() . Basically one can use site_url() while creating links for controllers whereas base_url() can be used where we need to create urls for the assets like loading a css or js file or some image .
What I always prefer is to use site_url() for creating links to controllers or ajax urls and base_url() for loading assets .

- 720
- 8
- 16