Welcome Guest, Not a member yet? Register   Sign In
css not showing with htaccess
#1

[eluser]frietkot[/eluser]
Hi,

I use a css file in my view file with this code
Code:
<?=link_tag('style.css');?>

and it works perfect.
But when i use my htaccess file
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

That works too but all my images and styles are not shown.

What is wrong?
#2

[eluser]mdowns[/eluser]
Add the stylesheet or images folder to the RewriteCond line:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
#3

[eluser]frietkot[/eluser]
thanks but same thing.
#4

[eluser]Nick Husher[/eluser]
You also need to update your links, so your .htaccess should have in it
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Your directory structure should look like this:
Code:
/
+ images
   + site-image-1.png
   + site-image-2.png
+ css
   + style.css

Your CI code should look like this:
Code:
<?=link_tag('css/style.css') ?>

And lastly, your CSS file should look like this:
Code:
.my-style .declaration {
  background-image: url(../images/site-image-1.png);
}
#5

[eluser]tsisson[/eluser]
I like this snippet better. Much more flexible, isn't it?
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#6

[eluser]frietkot[/eluser]
Thanks TSisson, easy and practical solution.
It works now




Theme © iAndrew 2016 - Forum software by © MyBB