【问题标题】:how to enable laravel 4 gzip?如何启用 laravel 4 gzip?
【发布时间】:2014-08-10 18:46:26
【问题描述】:

我的 laravel 4 项目中有两个 .htaccess 文件,一个在根目录中,另一个在公共文件夹中。我首先复制了这一行:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

因为我不想在域名后键入 /public,它可以工作,但是我复制了第二个 .htaccess 中启用 gzip 的代码,它会导致 500 内部服务器错误。 我从gziptest.com/faq 复制以下行,还尝试了许多其他文件,但没有一个对我有用。

   AddOutputFilterByType DEFLATE text/html
   AddOutputFilterByType DEFLATE text/plain
   AddOutputFilterByType DEFLATE text/xml
   AddOutputFilterByType DEFLATE application/x-javascript
   AddOutputFilterByType DEFLATE application/javascript
   AddOutputFilterByType DEFLATE text/javascript
   AddOutputFilterByType DEFLATE text/x-js
   AddOutputFilterByType DEFLATE text/css

   # Highest 9 - Lowest 1
   DeflateCompressionLevel 9

   # Skip browsers with known problems
   BrowserMatch ^Mozilla/4 gzip-only-text/html
   BrowserMatch ^Mozilla/4\.0[678] no-gzip
   BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

请帮帮我?

【问题讨论】:

  • OP,您还没有选择任何答案作为解决方案,有没有人设法解决您的问题?

标签: php .htaccess laravel-4 gzip


【解决方案1】:

我遇到了同样的问题,然后我去html5 boilerplate 的人那里尝试了一些东西,它对我有用。

这是sn-p:

<IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # https://developer.yahoo.com/blogs/ydn/pushing-beyond-gzipping-25601.html

    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Map certain file types to the specified encoding type in order to
    # make Apache serve them with the appropriate `Content-Encoding` HTTP
    # response header (this will NOT make Apache compress them!).

    # If the following file types wouldn't be served without the appropriate
    # `Content-Enable` HTTP response header, client applications (e.g.:
    # browsers) wouldn't know that they first need to uncompress the response,
    # and thus, wouldn't be able to understand the content.

    # http://httpd.apache.org/docs/current/mod/mod_mime.html#addencoding

    <IfModule mod_mime.c>
        AddEncoding gzip              svgz
    </IfModule>

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Compress all output labeled with one of the following media types.

    # IMPORTANT: For Apache versions below 2.3.7 you don't need to enable
    # `mod_filter` and can remove the `<IfModule mod_filter.c>` & `</IfModule>`
    # lines as `AddOutputFilterByType` is still in the core directives.

    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE "application/atom+xml" \
                                      "application/javascript" \
                                      "application/json" \
                                      "application/ld+json" \
                                      "application/manifest+json" \
                                      "application/rdf+xml" \
                                      "application/rss+xml" \
                                      "application/schema+json" \
                                      "application/vnd.geo+json" \
                                      "application/vnd.ms-fontobject" \
                                      "application/x-font-ttf" \
                                      "application/x-web-app-manifest+json" \
                                      "application/xhtml+xml" \
                                      "application/xml" \
                                      "font/opentype" \
                                      "image/svg+xml" \
                                      "image/x-icon" \
                                      "text/cache-manifest" \
                                      "text/css" \
                                      "text/html" \
                                      "text/javascript" \
                                      "text/plain" \
                                      "text/vtt" \
                                      "text/x-component" \
                                      "text/xml"
    </IfModule>

</IfModule>

【讨论】:

  • 这真的很有帮助,还有一点要补充,你必须启用 2 个模块 mod_deflate 和 mod_filter
【解决方案2】:

这是一个老问题,所以这可能对 OP 没有太大帮助,但我在处理相同问题时遇到了这个问题(修改 .htaccess 后出现 500 内部服务器错误)并认为它可能值得一提的是,以防其他人在这里遇到同样的问题。检查错误日志后,我发现了这个错误:

...无效命令“AddOutputFilterByType”,可能拼写错误或已定义 通过服务器配置中未包含的模块

所以在谷歌搜索之后,我找到了this in the Apache docs on upgrading to 2.4 from 2.2,上面写着:

无效命令“AddOutputFilterByType”,可能拼写错误或定义错误 通过服务器配置中未包含的模块 - AddOutputFilterByType 已从核心移至 mod_filter,其中 必须加载。

我运行的是 2.4,所以我检查了 httpd.conf 并取消了 LoadModule filter_module modules/mod_filter.so 的注释,这就成功了。

【讨论】:

  • 如果mod_filter 没有被激活,但你不希望出现500 内部服务器错误..., just wrap the AddOutputFilterByType` in &lt;IfModule mod_filter.c&gt;&lt;/IfModule&gt;
猜你喜欢
  • 2011-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-18
  • 2010-12-26
  • 1970-01-01
  • 2015-04-17
  • 2013-01-08
相关资源
最近更新 更多