Just thought I'd add some things that were important to me.
As you already mentioned, if you ever need to install Codeigniter in a subdirectory, the leading slash will certainly not work. You will need to specify the name of the subdirectory in the path. Personally, this is a lot, because we will install redesigns or prototypes in subdirectories. However, it can be nice (if applicable) to switch to SSL, if you do not already allow CI to automatically determine your base url (starting from version 2.0).
Changing your $config['base_url'] to not include the full domain might be a bad idea. At the top of my head, this will break the links and links in the emails sent by your application that use the base_url() function and, as a rule, can cause unexpected results.
Almost every HTML tag you need to use your base url, such as <link> <img> and <a> , is covered by the Codeigniter function. ( link_tag() , anchor() , img() ). They will take care of the base URL for you. (Why did they leave outside the <script> outside of me ...)
However, I agree - using the full base url adds a lot of extra page weight, especially in your navigation. Here is what I do to capture the path (in case of installing a subdirectory):
// constants.php $base_uri = $_SERVER['SCRIPT_NAME']; // Always index.php (bootstrap), right? $base_uri = str_replace('index.php', '', $base_uri); define('BASE_URI', $base_uri);
You can change this to a function or configuration item or something else, I prefer a constant. Then you can use:
<script src="<?php echo BASE_URI; ?>js/functions.js"></script>
This will usually be a long way to say / , but handles the problem with the subdirectory.
This may seem like a waste of time, but when you have many installations using the same code base, a smaller configuration is better.
source share