Link to CSS without /index.php/ in CodeIgniter
I have CodeIgniter without /index.php/ URL and i want to link CSS file in views.
My .htaccess:
RewriteEngine on
RewriteCond $1 !^([a-zA-z0-9/])
RewriteRule ^(.*)$ index.php [L]
RewriteCond $1 !^(index.php|images|robots.t开发者_如何学运维xt|system|user_guide)
RewriteRule ^(.*)$ index.php/$1 [L]
My link:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/views/metrohacker/style.css" />
With /index.php/ it works, but i want simple URL...
It's because your application folder isn't in the list of folders that aren't rewritten in your htaccess file.
RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide)
I would keep your CSS files in the root of the app rather than in the views folder. I would do the same with your JavaScripts and images too. That way your folder structure would be something like:
root/
application/
assets/
css/
js/
images/
system/
...
Make sure to add the assets folder to your .htaccess:
RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide|assets)
Then you don't have to worry about index.php doing the routing and you can just load a CSS file like so:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/style.css" />
精彩评论