Using CodeIgniter pretty URLs while having relative paths in the generated HTML.
This hook updates base_url config item depending on the current URL. For
/movies/view/125
base_url will be set to
../../
So
site_url('css/styles.css')
will generate
../../css/styles.css
system/application/config/config.php
$config['enable_hooks'] = TRUE;
system/application/config/hooks.php
// set base url $hook['post_controller_constructor'][] = array( 'class' => '', 'function' => 'rewrite_base_url', 'filename' => 'uri.php', 'filepath' => 'hooks' );
system/application/hooks/uri.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); function rewrite_base_url() { $n = count(explode('/', uri_string())) - 2; $str = ''; for ($i=0; $i < $n; $i++) { $str .= '../'; } $CI =& get_instance(); $CI->config->set_item('base_url', $str); } /* End of file uri.php */ /* Location: ./system/application/hools/uri.php */