javascript 使用 .htaccess 压缩文件时出现 500 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12182531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
500 error when compressing files with .htaccess
提问by believe me
I'm trying to compress files with .htaccess but I'm getting a 500 internal error,
我正在尝试使用 .htaccess 压缩文件,但出现 500 内部错误,
This is the code I'm trying to use.
这是我正在尝试使用的代码。
# JavaScript compression htaccess ruleset
AddHandler application/x-httpd-php .js
php_value auto_prepend_file gzip-js.php
php_flag zlib.output_compression On
I've also tried this but getting the same error,
我也试过这个,但得到同样的错误,
<files *.html>
SetOutputFilter DEFLATE
</files>
Any suggestions why?
任何建议为什么?
回答by Nilpo
Do you have mod_deflate
installed? Try this instead and see if your error goes away.
你mod_deflate
安装了吗?试试这个,看看你的错误是否消失。
<ifModule mod_deflate.c>
<Files *.html>
SetOutputFilter DEFLATE
</Files>
</ifModule>
If this resolves the 500 error, then you probably don't have mod_deflate
installed. You can test it by visiting HTTP Compression Test.
如果这解决了 500 错误,那么您可能还没有mod_deflate
安装。您可以通过访问HTTP 压缩测试来测试它。
If you have access, you may be able to enable it by uncommenting the following lines in your httpd.conf
file.
如果您有访问权限,则可以通过取消注释文件中的以下行来启用它httpd.conf
。
LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so
Then you will need to add an output type for each file type you wish to compress.
然后,您需要为要压缩的每种文件类型添加输出类型。
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
As mentioned in the comments, AddOutputFilterByType
depends on mod_filter
. If you still get a 500 error you should check that this module is loaded too.
正如评论中提到的,AddOutputFilterByType
取决于mod_filter
. 如果您仍然收到 500 错误,您应该检查该模块是否也已加载。
You can read more here: Use mod_deflate to Compress Web Content delivered by Apache
您可以在此处阅读更多信息:使用 mod_deflate 压缩 Apache 提供的 Web 内容
I can't find any documentation that suggests whether Siteground supports mod_deflate
or not. Their KB suggests using gZip from PHP.
我找不到任何表明 Siteground 是否支持的文档mod_deflate
。他们的知识库建议使用 PHP 中的 gZip。
How to enable gZIP compression for your pages?
How to compress my CSS with gZIP?
回答by believe me
回答by pcfede
## DEFLATE ##
#mod_filter.so and mod_deflate.so
##放气##
#mod_filter.so 和 mod_deflate.so
should be ON !!!!
应该开!!!
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
回答by Derk Jan Speelman
This worked fine for me (paste in .htaccess
):
这对我来说很好(粘贴.htaccess
):
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript