如何重写此RewriteRule?

时间:2008-12-08 19:34:09

标签: apache mod-rewrite

我有这个重写规则

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

匹配的东西:

somefolder/foo.css

并将它们重新编写为:

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

然而它不匹配:

foo.css

所以我尝试将其更改为:

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

然后它会重写为:

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

那我怎么能创建这个RewriteRule所以它可以重写foo.css来包含/ style / styleRedir.php?css = foo.css

1 个答案:

答案 0 :(得分:4)

我没有安装Apache来测试,但你尝试添加/?到第一组?

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

或者,为什么不是2个规则?

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