【问题标题】:htaccess - read image from own server if external image not foundhtaccess - 如果未找到外部图像,则从自己的服务器读取图像
【发布时间】:2023-03-27 01:14:01
【问题描述】:

我尝试了一些来自 stackoverflow 的代码示例,但似乎没有任何效果。

所以我有<img src="http://external-url.com/image.png" />,如果http://external-url.com/image.png 不存在,我想从我的服务器显示not-found.png。

我可以这样做吗?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此规则:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule \.(png|jpe?g|tiff|gif)$ /path/to/not-found.png [L,NC]
    

    /path/to/not-found.png 更改为not-found.png 的实际路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 2020-08-16
      • 2023-02-05
      • 1970-01-01
      • 2014-12-09
      相关资源
      最近更新 更多