Higeath
Higeath

Reputation: 561

Setting up caching in Apache2 on ubuntu 14.04

I'm trying to set up caching on my server this is my htaccess. The code is from different websites (caching code). I couldn't really find if in the newest version of apache mod_expires.c still is used and I also used command sudo a2enmod expires which worked then i restarted the web server. I'm using page insight to check if leverage/caching works but seems like it doesn't and even reloading the website I can see that images are downloaded and not loaded instantly.

ErrorDocument 404 /
ErrorDocument 403 /

Options ALL -Indexes

RewriteEngine On

RewriteEngine On


RewriteRule ^([0-9]+\.[^a-zA-Z]+)$ index.php?Patch_No=$1 [NC,L]

RewriteRule ^([0-9]+\.[^a-zA-Z]+)&([0-9a-zA-Z_-]+)$ index.php?Patch_No=$1&tab=$2 [NC,L]

RewriteRule ^patches php/patches.php [NC,L]

RewriteRule ^([^0-9][\s'0-9a-zA-Z_-]+[^0-9])$ index.php?Champion=$1 [NC,L]

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

Upvotes: 0

Views: 286

Answers (1)

Dhivin
Dhivin

Reputation: 706

sudo a2enmod file_cache



sudo service apache2 restart

open

 sudo nano /etc/apache2/apache2.conf

Add following lines under .htaccess

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

then

sudo service apache2 restart

Upvotes: 1

Related Questions