简体   繁体   中英

CodeIgniter URI routing: remove route segment from base URL

How do I remove a route segments from my base URL? For instance, I have these routes in my routes.php :

$route['default_controller'] = 'main_controller';
$route['users'] = 'user_controller';
$route['user/(:num)'] = 'main_controller/user/$1';

They all get routed normally, but in the view called by the user() method all of the generated links (for .js , .css , .png files, etc...) have user/ inserted betweem base URL localhost/domain_name and file path (eg css/style.css ), so all of those links (as you would expect) return 404 and the page isn't formatted properly.

If you need more info on the code in question, just comment what you need and I'll add it. Thanks in advance.

EDIT: If it's any help, echo base_url(); in the view prints out http://localhost/domain_name/ .

add base_url before the script and css files. and specify the folder in which is kept.Like we have style.css file in assets/css folder

<?php echo base_url('assets/css/style.css'); ?>
Or 
<?php echo base_url().'assets/css/style.css'; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM