【问题标题】:Serve static content for an RoR app using .htaccess使用 .htaccess 为 RoR 应用程序提供静态内容
【发布时间】:2010-11-30 16:56:08
【问题描述】:

我如何让用户能够将他们的内容上传到我的 RoR 应用程序,但随后可以访问此类静态内容:

  1. 由 APACHE Web 服务器提供 [以避免通过 Rails 的开销],但是

  2. 仍然希望在他们可以访问内容之前进行身份验证/授权检查

限制是我在 DreamHost 共享平台上,我只能访问 Apache .htaccess 文件,并且无法添加自己的 Apache 模块。

【问题讨论】:

    标签: ruby-on-rails apache .htaccess file-upload shared-hosting


    【解决方案1】:

    您可以重定向到静态内容,例如

    class ImagesController
      def show
        @image = Image.find(params[:id])
        if user_has_access_to @image
          redirect_to @image.bizarre_and_secret_image_location_that_is_served_by_apache
        else
          access_denied
        end
      end
    end
    

    当然,它不能完全保护内容。也许将静态 URL 设为临时会有所帮助:

    RewriteRule ^/images/RANDOMIZED_PREFIX_HERE/(.+)$ images/SECRET_IMAGE_LOCATION/$1 [L]
    

    ...现在每小时更改一次.htaccess 文件。当然,应用程序也应该知道前缀。

    【讨论】:

    • 谢谢,但我确实需要对物品进行适当的安全保护。因此,实际上更多的是关于我如何以编程方式在用户注册时安排 apache 可以提供无用的内容,但基于他们在应用程序中的凭据也希望无用的 HTML 页面本身在范围内
    猜你喜欢
    • 2020-03-06
    • 2016-05-02
    • 2015-05-24
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    相关资源
    最近更新 更多