Trik Base Site URL di file config.php

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

<?php
/*
|--------------------------------------------------------------------------
| 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

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

bls:

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...

regards,
Syamsul Bachri
IT Beginner
Computer Science, Bogor Agricultural University
http://syamsulbachri.co.cc

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.