Skip to main content

Trik Base Site URL di file config.php

October 24, 2008 by cahyono

cahyono's picture

Saya memakai trik di bawah ini untuk mendefinisikan $config['base_url'] di file config.php sehingga setiap kali tidak mengetik URL meskipun ganti2 folder:

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "index.php";
 
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|	http://example.com/
|
*/
//$config['base_url']	= "http://your-site.com/";
$http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
$fo = str_replace("index.php","", $_SERVER['SCRIPT_NAME']);
$config['base_url']	= "$http" . $_SERVER['SERVER_NAME'] . "" . $fo;

Comments

bisa juga dengan

December 29, 2008 by samsonasik, 2 years 31 weeks ago
Comment: 188

samsonasik's picture

bisa juga dengan menulisakan-nya seperti ini :
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/".$_SERVER['REQUEST_URI'] ;

bls:

February 13, 2009 by syabac, 2 years 25 weeks ago
Comment: 221

syabac's picture

kalo pake $_SERVER['REQUEST_URI'] bukannya bareng2 ama file yang direquest (biasanya index.php). kan pada base_url yang diminta sampai folder root dari project kita berada bkn??

mohon koreksi kalo salah...

bls:

November 11, 2008 by syabac, 2 years 38 weeks ago
Comment: 105

syabac's picture

oke jg...
jadi kita ga perlu nyeting base url-nya lagi seandainya pindah
hosting atau pindah folder..
(pernah juga sih kepikiran untuk begini)
good idea...

Premium Drupal Themes by Adaptivethemes