Welcome Guest, Not a member yet? Register   Sign In
Problems with $config['base_url']
#1

[eluser]bjuneau[/eluser]
Hello,

I noticed today that if I visit http://www.mysite.com/ some JS files aren't found using:
Code:
<?php echo base_url(); ?>dir/dir/something.js

However, if I switch to http://mysite.com/ it works just fine.

Code:
// config.php
$config['base_url'] = 'http://mysite.com/';

Code:
// autoload.php
$autoload['helper'] = array('url');

I host with MediaTemple and use their Grid package...


Thanks in advance! Smile
#2

[eluser]bjuneau[/eluser]
This fixed it:

Code:
// constants.php
$base_uri = $_SERVER['SCRIPT_NAME'];
$base_uri = str_replace('index.php', '', $base_uri);
define('BASE_URI', $base_uri);

Code:
src="<?php echo BASE_URI; ?>dir/dir/something.js"
#3

[eluser]Aken[/eluser]
I doubt that has anything to do with the base_url() helper. Check your .htaccess file or something.
#4

[eluser]boltsabre[/eluser]
And you're "double declaring" a variable.

Code:
$base_uri = $_SERVER['SCRIPT_NAME'];
$base_uri = str_replace('index.php', '', $base_uri);

can be replaced with
Code:
$base_uri = str_replace('index.php', '', $_SERVER['SCRIPT_NAME']);

Not a problem with how you have done it and it's completely unrelated to your question, this is merely a "coding tip". Less code, less chance for bugs.
#5

[eluser]InsiteFX[/eluser]
It should be like this.
Code:
<?php echo base_url('dir/dir/something.js'); ?>




Theme © iAndrew 2016 - Forum software by © MyBB