RewriteEngine on
# rewrite something like "www.bob.com/any/number/of/directories/css/file.css" to "www.bob.com/css/file.css"
RewriteRule css/(.*) /css$1
# do the same for js, gfx and file
RewriteRule js/(.*) /js$1
RewriteRule gfx/(.*) /gfx$1
RewriteRule file/(.*) /file$1
# everything else should be redirected to index.php which is in the document root
RewriteRule !(css|file|js|gfx)/ index.php
I've played around with about ten variations of this and I either get internal server errors or it doesn't do what I want. I have a feeling I need to use RewriteConds but you don't seem to be able to test them against the standard request string.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
# Skips the following S rules is they do not apply
RewriteRule ^.*$ - [S=1]
RewriteRule ^(.+)/css/file.css$ /css/file.css [QSA,L]
</IfModule>
Basically it needs to look at the url, regex everything that could contain */css/file.css and rewrite that to /css/file.css.
Take a look in the Apache, IIS, Web Servers forum, there is a sticky called Useful Resources that has a mod_rewrite cheatsheet that might be able to offer some assistance.
RewriteEngine On
# /anything/css/file.css -> /css/file.css
# directories are seperated by a | in the second ()
RewriteRule ^.+/(css|file|js|gfx)(/.*)?$ /$1$2 [L]
# ignore directories (from above)
RewriteRule ^(css|file|js|gfx)(/.*)?$ - [L]
# if it's not /index.php send it to /index.php
Rewriterule !^index\.php$ /index.php [L]