資料載入中

胡言亂語

.htaccess 使用gzip壓縮網站加快加載速度並節省頻寬

mod_gzip連結網址是Apache的外部擴展模組,可以將文件發送到客戶端之前快速輕鬆地對其進行壓縮。

如果您的託管服務提供商已啟用mod_gzip模塊,則壓縮內容的最佳方法是在.htaccess文件中添加以下幾行:
<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>

如果網站空間商沒有啟用此模塊?

則可以添加以下:
php_value output_handler ob_gzhandler

這可以讓PHP可以壓縮您的PHP文件(但請謹慎使用,因為這會佔用大量CPU)。

以上資訊紀錄~

  • mod_gzip壓縮模組的使用方法
  • Apache伺服器的外部擴展模組
  • 如何在.htaccess文件中添加壓縮設置
  • PHP文件壓縮對CPU的影響
  • 託管服務提供商啟用mod_gzip的必要性
https://innstory.com/story-htaccess使用gzip壓縮網站加快加載速度並節省頻寬-2712

上一篇
 PHP如何移除xpoweredby資訊

下一篇
使用htaccess中更改sessionname 

發表留言

  • Angela

    這段關於mod_gzip的資訊很實用,特別是對於網站優化的部分。看來壓縮文件也是需要考慮的細節呢。
    2026-04-02 下午 9 點回覆

作者簡介

離不開電腦的宅男


推薦閱讀

作者其他相關類別故事

mysql 查詢數據資料是否有重複

mysql 查詢數據資料是否…

Mark Chang 8 年又 71 天 2.4K

有沒有試過資料庫裡上萬筆資料卻不知道是不是有重複的數據? 這時你一定要試試這個查詢方法~  

改變input placeholder 字體顏色

改變input placeh…

Mark Chang 7 年又 302 天 2.5K

通常我們會使用 placeholder 來作為欄位提醒文字~ 通常 placeholder 字體...

Ubuntu環境下apache 目錄啟動.htaccess 功能

Ubuntu環境下apach…

Mark Chang 5 年又 229 天 2.8K

.htaccess 檔案是目錄層面的設定檔,可以對目錄變更 Apache 的設定。 要使用 .ht...