CI base_url()混淆

say i have this code,

<a href="register">Join</a>

that link would be on the homepage, the url of that homepage would be,

localhost/Project/main

main is the controller and there is an index function that loads the view for the homepage. I set up the header navigation and footer as templates so in my index function i'd have.

        $this->load->view('templates/header');
        $this->load->view('templates/navigation');
        $this->load->view('homepage');
        $this->load->view('templates/footer');

When i click on the join link which is located in the navigation template, the url will be,

localhost/Project/main/register

on the register function on main controller i put a simple echo function to see if it works and it is working.

the problem is that im confused, i searched on how to properly link from views to another views in CI and i am seeing the base_url() or site_url() function used, i use base_url because i took out the index.php on my link with .htaccess

the confusion is that if i use the base_url() function say,

<a href="<?php echo base_url(); ?>main/register">Join</a>

and ofcourse the base_url on my config is localhost/Project/, so i expect the link to also go to the main/controller and be like,

localhost/Project/main/register but what i get is,

http://localhost/Project/localhost/Project/main/register

What im confused is that i am thought or still am thinking that if i ever click on the link by url would refresh or something. or am i wrong?

i know my confusion may seem simple to others but atm im too muddleheaded that i don't have any idea where i am supposed to go to clarify this. although i could just use the first i just want to understand why..

No index.php

You've probably done this already, but just to be complete...

If you want to have your addresses without the index.php in them, you need to do two things:

First, remove the index.php from your config.php.

On line 32, change:

$config['index_page'] = 'index.php';

to:

$config['index_page'] = '';

Second, add rewrite to your .htaccess.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

base_url() or site_url()

CodeIgniter tries to guess the base_url of your website, if it's wrong, you can change it in your config.php file on line 20, just above the index_page. It is encouraged that you set this manually.

base_url() prints, as its name suggests, the base URL that is either set in your config.php file, or guessed by CodeIgniter. Use this for example to provide absolute paths to css or js files, for example:

<link rel="stylesheet" type="text/css" href="<?=base_url()?>assets/style.css">

site_url() generates the whole URL for your controller/method. Use it like this:

<a href="<?=site_url('main/register')?>">Register</a>

If your base_url is for example http://localhost/Project/, this will generate http://localhost/Project/main/register.