$100 Website Offer

Get your personal website + domain for just $100.

Limited Time Offer!

Claim Your Website Now

How to setup caching & GZIP compression in Apache Web Server with .htaccess

To setup caching and GZIP compression in Apache Web Server with .htaccess, follow these steps:

  1. Enable mod_deflate: First, you need to enable the mod_deflate module in your Apache web server. You can do this by adding the following line to your Apache configuration file (httpd.conf):
LoadModule deflate_module modules/mod_deflate.so
  1. Create .htaccess file: Next, create a new file named .htaccess in the root directory of your website.
  2. Enable GZIP compression: Add the following lines to your .htaccess file to enable GZIP compression:
# Enable GZIP compression
<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>
  1. hese lines will tell Apache to compress the specified file types before sending them to the user’s browser.
  2. Set caching rules: Add the following lines to your .htaccess file to set caching rules:
# Set caching rules
<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=86400, public"
</FilesMatch>
</IfModule>
  1. These lines will set caching rules for the specified file types. The “max-age” value tells the browser to cache the files for a certain amount of time (in seconds).
  2. Save the .htaccess file: Save the changes to your .htaccess file and upload it to the root directory of your website.
  3. Test your website: Test your website using Google PageSpeed Insights or other similar tools to verify that GZIP compression and caching are working properly.

Note: These steps assume that you have access to the Apache configuration file and the ability to enable modules. If you are on a shared hosting plan, you may not have access to these settings and will need to contact your hosting provider for assistance.

Related Posts

Navigating Legal Care in India: How to Evaluate Advocates, Practice Areas, and Consultations

Introduction Facing a legal question, business compliance issue, or court dispute can feel overwhelming. Whether you are dealing with a property transaction, a family dispute, an employment…

Read More

Navigating International Dental Care: How to Evaluate Hospitals, Dentists, and Treatment Abroad

Introduction Choosing a dental provider is one of the most critical health decisions a person can make, especially when considering travel outside one’s home country. Today, millions…

Read More

Navigating Modern Indian Taxation, Business Compliance, and Strategic Financial Advisory

Introduction Managing personal finances, scaling a startup, or running an established corporate enterprise in India requires strict adherence to an evolving regulatory landscape. From seasonal tax updates…

Read More

Navigating the Modern Event Ecosystem: Event Discovery, Digital Ticketing, and Management in Bangalore

Introduction Bangalore—often celebrated as India’s Silicon Valley and cultural melting pot—pulses with non-stop energy. On any given day, thousands of working professionals, students, creators, startup founders, and…

Read More

Evaluating Business Software, AI Platforms, and Enterprise Technology Solutions

Introduction The modern enterprise software ecosystem is expanding at an unprecedented rate. From cloud-native SaaS applications and AI-driven workflow engines to complex infrastructure management frameworks, technology leaders…

Read More

Enterprise AI Training and Certification Guide for Modern Professionals

Introduction Artificial intelligence has rapidly evolved from an experimental sandbox project into a fundamental core infrastructure requirement for global enterprises. Organizations across every sector are no longer…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x