so basically when i echo the codeigniter function base_url() in the href attribute of an anchor tag, it appears to echo it out twice. Example:
<a href="<?php echo base_url(); ?>">somelink</a>
and the above, if you inspect it your chrome browser shows this:
<a href="www.mysitedomainname.com/www.mysitedomainname.com/">somelink</a>
"mysitedomainname.com" is just a name i made up for this example. Any reason why this is happening?
base_url is without the index_page or url_suffix being appended. like site_url , you can supply segments as a string or an array. If you want a URL access to a resource use base_url you can supply a string to a file, such as an image or stylesheet else site_url is enough.
base_url() is the URL of your CodeIgniter root or the location of the index. php file along with a trailing slash appended to the end of the URL. If the domain name is example.com and the website is using HTTPS as well as www. Further, the index.
The base URL of the site can be configured in application/config/config. php file. It is URL to your CodeIgniter root.
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.
There are three reasons I'm aware about that can cause this.
The first one is when something wrong is written in config.php
on line 17 $config['base_url'] = '';
- it better be left empty, just like when you download CI.
The second one is if you have set $config['base_url']
value to something without prefixing it with http://
or other protocol.
The third one is if you have set base
href
somewhere:
<base href="http://www.mysitedomainname.com/" />
When you need to link to some other page, you should use site_url()
, base_url()
can be used to link stylesheets, js, img src attributes and other real URL's. The reason is pretty simple, base_url()
does not include the index_page
value set in config.php
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With