How can I rewrite this RewriteRule?

I have this rewrite rule

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

which matches the type:

somefolder / foo.css

and rewrites them:

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

however it won't match:

foo.css

So I tried to change it to:

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

but then he will rewrite:

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

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

0


source to share


1 answer


I don't have Apache installed for testing, but have you tried adding /? to the first group?

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

      



Alternatively, 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]

      

+4


source







All Articles