1

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

1 Answer 1

7

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" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.