Here are examples of how to use the mod_expires, mod_headers, and mod_deflate

Examples of Using mod_expires

Caching Images for One Month:

apache
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpeg "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/gif "access plus 1 month" </IfModule>

Caching CSS and JS Files for One Week:

apache
<IfModule mod_expires.c> ExpiresActive On ExpiresByType text/css "access plus 1 week" ExpiresByType application/javascript "access plus 1 week" </IfModule>

Disabling Caching for HTML Pages:

apache
<IfModule mod_expires.c> ExpiresActive On ExpiresByType text/html "access plus 0 seconds" </IfModule>

Examples of Using mod_headers

Setting Cache-Control Header for All Resources:

apache
<IfModule mod_headers.c> Header set Cache-Control "max-age=3600, public" </IfModule>

Setting Content-Security-Policy Header:

apache
<IfModule mod_headers.c> Header set Content-Security-Policy "default-src 'self';" </IfModule>

Setting Strict-Transport-Security Header:

apache
<IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" </IfModule>

Example of Using mod_deflate for Data Compression

Compressing Text Files:

apache
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript </IfModule>

Disabling Compression for Old Browsers:

apache
<IfModule mod_deflate.c> SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary </IfModule>

Combining and Minimizing Files:

apache
<IfModule mod_deflate.c> AddOutputFilter DEFLATE js css </IfModule>

These configurations help enhance website performance by setting proper caching policies, adding security headers, and enabling data compression. Adjust these settings based on your specific requirements to optimize your Apache server.

  • хостинг, htaccess
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

HTTP Errors: common causes and how to fix them

Error 403: ForbiddenDescription: The server understands the request but refuses to fulfill it....

Configuring DNS on Cloudflare

Cloudflare is a popular service that provides protection and performance improvements for...

Here are 10 examples of using redirects in an .htaccess file

1. Redirect from One Page to Another Redirect a specific page to a new page: apache...

Connecting to hosting via FTP using FileZilla

FileZilla is a simple and convenient tool for managing files on your server. Here’s a...

What is a subdomain and how is it used?

A subdomain is a part of a domain name that is added before the main domain name. It is used to...

Powered by WHMCompleteSolution