【问题标题】:Different image URL than actual file path in PHP与 PHP 中的实际文件路径不同的图像 URL
【发布时间】:2016-02-02 17:57:58
【问题描述】:

我正在使用 Yii 框架。我在上传/产品中有一个产品图片文件夹。我想在页面视图源中显示图像 src,如下所示:

<img src="product1.jpg" >

代替:

<img src="uploads/products/product1.jpg" >

请帮我解决这个问题。

【问题讨论】:

  • 很好。祝你好运。你有问题吗?

标签: .htaccess url yii url-rewriting


【解决方案1】:

您可以使用.htaccess file 进行此类重定向。您需要 Apache 模块 mod_rewrite 来执行此操作,但它通常默认加载/启用。

【讨论】:

    【解决方案2】:
    RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png|ico)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*)$ uploads/product/$1 [L]
    

    这里我们在 htaccess 中检查具有以下扩展名 (jpg|jpeg|gif|png) 的文件,如果文件没有退出,那么将检查 uploads/product/ 文件夹中的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      相关资源
      最近更新 更多