views:

133

answers:

4

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 :).

A: 

If I understand correctly you wish to exclude the folder /ssi/? If so use a rule like this (in htaccess):

RewriteRule ^(folder|file\.php)

in your case:

RewriteRule ^(ssi)

Jakub
A: 

... it assumes the css is located in /whatever/ssi/*.css.
I just want to be able to write a condition that says "if it's a css file, don't apply these rules."

This translates directly to

RewriteCond %{REQUEST_URI} !^/whatever/ssi/[^/]+\.css$
RewriteRule ...
Artefacto
+1  A: 

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
cleek
I believe you're correct now that I think more on it. I'm using XAMPP with a projects folder. So when I do href="ssi/main.css" it appends that to the current url, which is wrong. If I do href="/ssi/main.css", it does http://localhost/ssi/main.css. It should be going to http://localhost/projects/asdf/ssi/main.css. Is there any way to setup XAMPP/apache to have multiple root dirs based on the project folder?
Will
No, I don't think you can have multiple root dirs for a project. But if all of your css truly is in /ssi, why not simply make the path /ssi/*.css?
cleek
Because, like I said, I have multiple projects. So if I were to do that, it would point to http://localhost/ssi/*.css instead of http://localhost/projects/asdf/ssi/*.css where it's actually housed.
Will
Then you may unfortunately be left with the option of creating RewriteRules as I described earlier. Of course, you could just specify a server relative path: /theproject/ssi/style.css
cleek
I'm looking into Virtual Hosts. Possibly setup a subdomain for each project. If I can get that to work it would alleviate all my problems :).
Will
Yes, virtual hosts would definitely solve the problem for you.
cleek
Got it all setup, seems to be working swimmingly. Thank you for all your help, everyone :).
Will
A: 

Anticipating you're using Apache with mod_rewrite module, you should try the RewriteCond Directive. The following example excludes all the matches from RewriteCond for the following line with the RewriteRule Directive. The rules are basically regular expression. The one in my example excludes everything which starts with either favicon.ico as well as with css, which is the folder, where my Stylesheets resides.

RewriteEngine On
RewriteCond $1 !^(favicon\.ico|favicon\.png|media|robots\.txt|crossdomain\.xml|css|js)
RewriteRule ^(.*)$ index.php/$1 [L]

Further reading: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

matths
Thank you so much. I believe my problem has been narrowed down more to having relative paths in my markup. I'm running XAMPP with a projects folder so if I do /ssi/main.css, it does http://localhost/ssi/main.css when it should be http://localhost/projects/asdf/ssi/main.css. Is there any way around this that you know?
Will