views:

325

answers:

1

I have this rewrite rule

RewriteRule (.*)/([^/\.]+).css$ include/style/styleRedir.php?css=$2.css [L,NC]

which matches thing like:

somefolder/foo.css

and rewirites them to:

include/style/styleRedir.php?css=foo.css

however it won't match:

foo.css

So I tried changing it to:

RewriteRule (.*)(/?)([^/\.]+).css$ include/style/styleRedir.php?css=$3.css [L,NC]

but then it would rewrite to:

include/style/styleRedir.php?css=.css

So how could I make this RewriteRule so it can rewrite foo.css to include/style/styleRedir.php?css=foo.css

+3  A: 

I don't have Apache installed to test, but have you tried adding the /? to the first grouping?

RewriteRule (.*/?)([^/\.]+).css$ include/style/styleRedir.php?css=$2.css [L,NC]

Alternately, why not 2 rules?

RewriteRule (.*)/([^/\.]+).css$ include/style/styleRedir.php?css=$2.css [L,NC]
RewriteRule /?([^/\.]+).css$ include/style/styleRedir.php?css=$1.css [L,NC]
Chris Marasti-Georg
Thank you, solution 2 (2 rules) fixed it.
Pim Jager