【问题标题】:Apache rewrite to other directory, if file exists thereApache重写到其他目录,如果文件存在那里
【发布时间】:2012-06-29 12:52:29
【问题描述】:

我的目录如下所示:

/assets
  /images
    /2011
    /2012
  /images-hq
    /2011
    /2012

在 html 文件中,每张图片都有一个类似的标签:

<img src="/assets/images/2012/example.jpg" />

我想检查一下,images-hq 文件夹中是否存在相同的图像,如果存在,我想将该图像发送给用户。

例子:

/assets/images/2012/example.jpg to /assets/images-hq/2012/example.jpg

如果 /assets/images-hq/2012/example.jpg 存在,如果不存在,则提供原件。

【问题讨论】:

    标签: apache mod-rewrite rewrite exists


    【解决方案1】:

    我试过这样做,似乎可行:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} (.*)/[a-z]+/(.+)\.(gif|jpe?g|png)$
    RewriteCond %1/images-hq/%2.%3 -f
    RewriteRule (.*)/[a-z]+/(.+)\.(png|jpg|jpeg)$ %1/images-hq/%2.%3 [L]
    

    我基于this solution

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2012-04-23
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多