簡體   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