How to add automatic base URL in Codeigniter?

How to add automatic base URL in Codeigniter?

Are you tired of changing script path each time you more your script into different locations. Here is a trick, so that you can automatically get base_url without changing each time you move your code.

Change $config['base_url'] into this syntax.

defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');

$config['base_url'] = BASE_URL;

Here is another tutorial to remove index.php from Codeigniter URL.

If you liked this article, then please subscribe to our YouTube Channel for useful videos. You can also find us on Twitter and Facebook.

About the author

Ishwar Acharya

I am a web designer and developer and keen on contributing to the web development industry since last 10 years. I love PHP development and absolutely amazed by front-end js libraries such as React, VueJs etc. Feel free to follow me @imishwaracharya on twitter.

Write a Reply or Comment

Your email address will not be published. Required fields are marked *

No Comment

This post has not been commented yet.

The Webography