Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude CSS, JS, JPG, GIF files from mod_rewrite rules?

This is what I have so far:

RewriteRule ^([A-Za-z0-9_]*)/?$ index.php?page=$1 [NC]
RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2 [NC]
RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2/$3 [NC]

All of my css files are located in /ssi/.

The site structure itself is /index.php?page=$whatever

$whatever sometimes includes /'s, so if I go to /whatever/whatever2, with my current rules, it assumes the css is located in /whatever/ssi/*.css.

I hope all of that makes sense.

So, basically I just want to be able to write a condition that says "if it's a css file, don't apply these rules."

Thank you for any help I can get :).

like image 339
Will Avatar asked Oct 25 '25 06:10

Will


1 Answers

The problem that you are experiencing is not that the mod_rewrite is being applied to css files, but rather that the paths in your html to your css is relative. The browser is simply requesting the css from the correct relative path. You really have two options.

  1. Make your paths to your css relative to the domain instead of to the page (e.g. use /ssi/styles.css instead of ssi/styles.css)
  2. Create a rewrite rule to redirect all css to the correct URL. (e.g. RewriteRule (*.css) /ssi/$1
like image 86
cleek Avatar answered Oct 26 '25 20:10

cleek