【问题标题】:Slim Framework 3 RESTful Backend - Serving ImagesSlim Framework 3 RESTful 后端 - 提供图像
【发布时间】:2017-08-05 13:40:04
【问题描述】:

在我的网络应用程序上上传图像时,图像存储在/public/uploads/ 目录中。对于熟悉 Slim Framework 3 的人来说,/public/ 目录是存储index.php 的地方。

仅导航到 http://website.com/uploads/image.png 不起作用,我认为它会寻找 Slim 3 路线?

为了让我在导航到图像时预览图像,我是否必须在我的 REST 应用程序中创建自定义路由?

.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

【问题讨论】:

  • 显示你的.htaccess-file。
  • @jmattheis 添加了我的 .htaccess

标签: php rest slim-3


【解决方案1】:

我只是简单地在我的上传目录中创建了一个新的.htaccess 文件,它就起作用了。

我的文件联系了以下RewriteEngine Off

【讨论】:

    【解决方案2】:

    试试这样的。 (我没有检查代码)。

    RewriteEngine On
    
    //Is file not exist then rewrite to index.php 
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} !-f
    RewriteRule ^ index.php [QSA,L]
    
    // file exist then rewrite to new path and try again with new path.
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
    RewriteRule ^(.*)?$ /public/$1 [QSA,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 2021-06-24
      • 2013-07-24
      • 1970-01-01
      相关资源
      最近更新 更多