繁体   English   中英

如何在1and1服务器托管的网站上启用gzip

[英]How to enable gzip on a website hosted on 1and1 server

我已经读过这里的话题。 但我无法对此发表评论。 因此,我在文件php.ini中进行了更改

zlib.output_compression =1
zlib.output_compression_level =9

(在我的情况下,我使用compression_level = 5)。

在这里测试gzip >> GIDZipTest和这里>> HTTP压缩测试我看到它正在工作。

但是,指南中还有另一步。 第二步是编辑文件.htaccess。 但是这是我的问题:

我有这个.htaccess文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

AddHandler x-mapp-php5.5  .php

主题建议在文件.htaccess中放入以下内容:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$ 
RewriteCond %{REQUEST_FILENAME}.gz -f 
RewriteRule (.+) $1.gz [QSA,L] 
</IfModule>

如您所见,它是相似的。 如何在文件中添加所有内容?

1)我应该在一个文件中实现不同的行,例如:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$ 
RewriteCond %{REQUEST_FILENAME}.gz -f 
RewriteRule (.+) $1.gz [QSA,L]
</IfModule>

# END WordPress

AddHandler x-mapp-php5.5  .php

2)或者我应该做两个不同的部分,例如:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$ 
RewriteCond %{REQUEST_FILENAME}.gz -f 
RewriteRule (.+) $1.gz [QSA,L] 
</IfModule>

# END WordPress

AddHandler x-mapp-php5.5  .php

要不然是啥?

谢谢!

您最好将它们分别添加。 基本上,WordPress可以更改WordPress的开始和结束注释之间的任何内容。 因此,您绝对不应在两者之间添加任何内容(除非WP显然告诉您)。

因此,对于gzip-假设此代码正确,但我没有验证-您可以这样做:

# BEGIN gzip
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$ 
RewriteCond %{REQUEST_FILENAME}.gz -f 
RewriteRule (.+) $1.gz [QSA,L] 
</IfModule>
# END gzip

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

AddHandler x-mapp-php5.5  .php

但是,当您的gzip已在工作时,则无需添加它。 也许您使用的插件可以解决这个问题,例如W3 Total Cache?


更新:

我对zlib不熟悉。 根据您所引用的消息来源,这是针对动态内容(例如php)的,而.htaccess中添加的内容是针对静态内容(例如样式表和Javascript)的。 因此,除非您有一个负责压缩的插件,否则可能不是您网站上的所有内容都被压缩了。 验证这一点可能会很好。 另外,如果您使用缓存,则所有内容可能都是静态(HTML),在这种情况下,.htaccess可能更相关。 我建议尝试一下。

作为记录,在切换到W3TC之前,我在.htaccess中使用了此文件进行gzip压缩:

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

我不知道它是否适用于1and1。


更新2:1&1在其“性能”服务器上为gzip 建议以下内容:

<IfModule mod_deflate.c>
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
</IfModule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM