Examples of Using mod_expires
Caching Images for One Month:
<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:
<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:
<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:
<IfModule mod_headers.c>
Header set Cache-Control "max-age=3600, public"
</IfModule>
Setting Content-Security-Policy Header:
<IfModule mod_headers.c>
Header set Content-Security-Policy "default-src 'self';"
</IfModule>
Setting Strict-Transport-Security Header:
<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:
<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:
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
</IfModule>
Combining and Minimizing Files:
<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.