【问题标题】:How do I rewrite this RewriteRule?如何重写这个 RewriteRule?
【发布时间】:2008-12-08 19:34:08
【问题描述】:

我有这个重写规则

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

与以下内容匹配:

某个文件夹/foo.css

并将它们重写为:

包括/样式/styleRedir.php?css=foo.css

但它不匹配:

foo.css

所以我尝试将其更改为:

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

但它会重写为:

包括/样式/styleRedir.php?css=.css

那么我怎样才能使这个 RewriteRule 可以重写 foo.css 以包含/style/styleRedir.php?css=foo.css

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    我没有安装 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]
    

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2014-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2014-06-11
      相关资源
      最近更新 更多