CodeIgniter Forums
css not showing with htaccess - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: css not showing with htaccess (/showthread.php?tid=12137)



css not showing with htaccess - El Forum - 10-07-2008

[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?


css not showing with htaccess - El Forum - 10-07-2008

[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]



css not showing with htaccess - El Forum - 10-07-2008

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


css not showing with htaccess - El Forum - 10-07-2008

[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);
}



css not showing with htaccess - El Forum - 10-07-2008

[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]



css not showing with htaccess - El Forum - 10-08-2008

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